当我尝试连接SQL Server时,我得到以下错误:

在建立与SQL Server的连接时,发生了与网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否正确,SQL Server是否配置为允许远程连接。(提供商:Named Pipes提供商,错误:40 -无法打开到SQL Server的连接)

当我试图在Visual Studio 2010中将数据库配置为gridview时抛出此错误。我不知道如何调试这个错误。

如何调试此错误?除了错误消息中提到的步骤之外,我还应该采取哪些步骤来确定这里到底发生了什么?


当前回答

对我来说,解决方案是调用互联网提供商开放端口1433。

出于某种原因,他们阻塞了端口,我甚至无法ping数据库服务器(托管在Azure上)。100%的数据包丢失。

他们打开港口后,一切又恢复了正常。

其他回答

我必须运行SQL Server浏览器服务到SQL Server配置管理器。 如果没有这个,安装就不能发现新创建的服务。

I got this error after working at distance (VPN) for a few years. At some point in time I must have changed my DNS settings to the IP address of my home router. Now I was (again) in the same network as the server, and got the error above. the solution was to open "Network status" / "Change adapter options" and right click the active internet connection (Ethernet in my case) to get to the properties of IPv4. Under "Use the following DNS server addresses" I entered the local IP address of my server, and what do you know...! The computer contacted the domain (on the server) and SQL Server opened up.

要检查是否有相同的问题,打开cmd并输入 夜间电报/ dsgetdc:域名 [用域名交换"domainname"] 如果您得到一条消息说“获取DC名称失败:Status = 1355 0x54b ERROR_NO_SUCH_DOMAIN”,您可能是域名错误,或者您可能有这个问题。

这也可能是简单的事实,你的数据库实际上不是MS SQL Server。例如,如果你的数据库实际上是MySql,你试图用System.Data.SqlClient连接它,你会得到这个错误。

到目前为止,大多数ADO的例子。Net将用于MSSQL,没有经验的用户可能不知道你不能在MySql中使用SqlConnection, SqlCommand等。

虽然所有的ADO。Net数据提供程序遵循相同的接口,您必须使用为您的数据库提供程序。

重启SQL Server (MSSQLSERVER)服务即可。

验证用于为SQL Server实例创建会话的帐户。