SQL Server 2005 Pitfalls

time to read 2 min | 329 words

Okay, this one is a tiny pitfall, but it really drove me mad. I was developing a web service that needed to talk to a database. But nothing that I could do would make it do it. It kept giving me this error:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I wasn't connecting remotely, both the web service and the server were on the same machine, and I could access it via Management Studio. I then though about permissions, even though the error message wasn't the right one for that, so I granted the ASPNet account so much permissions that it cried foul. No go with that. I realized that I was using the ASP.Net Development Server, so it was running under my account all along, so it couldn't be this.

In the end, the devil was in the details, I was using this connection string:

Data Source=(localhost);Initial Catalog=Test;Integrated Security=True

To make it work, I need to change it to:

Data Source=localhost;Initial Catalog=Test;Integrated Security=True

Apparently the two are not equivalent, the first uses TCP/IP (which was disabled), the second uses Named Pipes (which worked).