简体   繁体   English

SQL Server连接问题

[英]SQL Server connection issue

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. 我在Windows Server 2003上使用VSTS 2008 + .Net 3.5 + C#+ SQL Server 2008 Enterprise。我使用以下连接字符串,而labtest1是本地计算机名称,我使用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. 但是,当我将连接字符串从“ labtest1”更改为“。”时,使用相同的ADO.Net客户端代码连接就不会出现问题。 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. System.Data.SqlClient.SqlException:建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

Looks like a Sql Server configuration issue to me : have you tried to tune protocols in Sql Server Network configuration ? 在我看来,这是一个Sql Server配置问题:您是否尝试过调整Sql Server网络配置中的协议? Named Pipes or TCP/IP should be enabled. 应该启用命名管道或TCP / IP。

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". 或“(本地)”它连接到PC上的默认实例,也许SQL Server随实例一起安装,在这种情况下,您必须以“ SERVER \\ INSTANCE_NAME”格式在连接字符串中指定实例名称。

In SQL Management studio execute this query to see your full server\\instance name 在SQL Management Studio中,执行此查询以查看完整的服务器\\实例名称

select @@servername

I have seen this issue previously with ZoneAlarms blocking the connection (on the machine trying to connect to the SQL server). 我以前曾在ZoneAlarms阻止连接(在试图连接到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) (在SQL Server配置管理器-sql server 2005中,这就是我所拥有的,在2008年可能有所不同-您应该能够验证此设置)

Try to ping by the computer name: ping labtest1 . 尝试按计算机名ping labtest1ping labtest1 if it does not find the server, then try ping labtest1.mydomainname.com with the domain name. 如果找不到服务器,请尝试使用域名ping labtest1.mydomainname.com If this works, then you just need to add/fix the DSN aliases in the domain controller or just re-login to the machine. 如果这行得通,那么您只需要在域控制器中添加/修复DSN别名,或者仅重新登录计算机即可。

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. 我希望看到:连接字符串中的Integrated Security = True(假定其为本地计算机)。

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. 可能相关的另一件事是-如前所述-协议,我希望确保已启用TCP / IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM