I am using VSTS 2008 + .Net 3.5 + C# + SQL Server 2008 Enterprise on Windows Server 2003. I am using the following connection string, and labtest1 is the local machine name and I connect from local machine using ADO.Net. Then it always fail with connection error. But when I change in the connection string from "labtest1" to ".", connection has no issue with the same ADO.Net client code. Any ideas what is wrong?

Data Source=labtest1;Initial Catalog=CustomerDB;Trusted_Connection=true;Asynchronous Processing=true

Here is the detailed error message I got,

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

thanks in advance, George

  • 1
    please post the error your getting – Nick Kavadias Oct 16 '09 at 7:52
  • I have posted my detailed error message, any ideas what is wrong? – George2 Oct 16 '09 at 7:54

Yeah, looks like your trying to connect with named pipes. Try adding DBMSSOCN=TCP/IP to your connection string, or try a few different settings, This should help.

Check that SQL Server has tcp/ip enabled in configuration manager, remote connections are allowed and there is no firewall blocking connectivity to port 1433. Follow the troubleshooting steps in this blog.

  • It returns labtest1. Any further ideas? – George2 Oct 16 '09 at 8:40
  • After enable Named Pipe in SQL Server Configuration Manager, it works. Why SQL Server will use named pipe? I think TCP/IP should be used? – George2 Oct 16 '09 at 8:42
  • In my knowledge, I think TCP/IP should be used as default protocol. Why Named Pipe is used? Because I connect locally on the same machine? – George2 Oct 16 '09 at 13:53
  • Final question, how to know which protocol (TCP/IP or Named Pipe) is used? In my connection string, I do not assign TCP/IP or Named Pipe, so I am really confused which protocol is used? – George2 Oct 18 '09 at 16:36
  • 1
    Check what options your server in allowing under protocols in SQL Server Configuration Manager – Nick Kavadias Oct 18 '09 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.