开发者

SQL Server connection issue

开发者 https://www.devze.com 2022-12-08 10:45 出处:网络
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 ma

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 machin开发者_如何转开发e 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)


Looks like a Sql Server configuration issue to me : have you tried to tune protocols in Sql Server Network configuration ? Named Pipes or TCP/IP should be enabled.


When you use "." or "(local)" it connects to the default instance on your PC, perhaps the SQL Server was installed with instances, in which case you have to specify the instance name in the connection string in the format "SERVER\INSTANCE_NAME".

In SQL Management studio execute this query to see your full server\instance name

select @@servername


I have seen this issue previously with ZoneAlarms blocking the connection (on the machine trying to connect to the SQL server). I would spend some time investigating this area around firewalls etc.

Hope this helps


Do you have the Named Pipes network protocol enabled in the network config? (In the SQL Server Configuration Manager - sql server 2005, that's what I have, might be different in 2008 - you should be able to verify this setting)


Try to ping by the computer name: ping labtest1. if it does not find the server, then try ping labtest1.mydomainname.com with the domain name. If this works, then you just need to add/fix the DSN aliases in the domain controller or just re-login to the machine.


One other thins - and may not be relevant - but you've not specified the security model, at least not in the string provided as a sample.

I would expect to see: Integrated Security=True (given that its the local machine) in the connection string.

The other thing that may be relevant is - as has already been mentioned - the protocols, I'd look to make sure that TCP/IP is enabled.

0

精彩评论

暂无评论...
验证码 换一张
取 消