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

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

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

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


当前回答

当我试图从其他网络访问mssql服务器时,我得到了解决方案:

Open "SQL Server Configuration Manager"

Now Click on "SQL Server Network Configuration" and Click on "Protocols for Name"

Right Click on "TCP/IP" (make sure it is Enabled) Click on Properties

Now Select "IP Addresses" Tab -and- Go to the last entry "IP All"

Enter "TCP Port" 1433

为1433端口添加入站+出站规则

其他回答

即使我使用了正确的凭证,我也面临着这种问题。请务必执行以下操作。

确保您的sql server凭据。在sql server字段中,您必须使用计算机名。

要找到计算机名称,在您的计算机上搜索计算机名称,然后就可以找到计算机名称。然后粘贴并尝试连接。

如果无法正常工作,请尝试从服务启动计算机上的sql server。下面的截图会有帮助。

用于远程服务器数据库连接。 如果没有一个答案让你满意,很可能你还没有添加SQL端口1433到Windows防火墙例外。请执行以下步骤。

进入开始菜单,打开运行类型WF.msc。 在Windows防火墙高级安全。 添加入站规则。 添加1433端口。 说出你的规则。 重新启动SQL服务。

有关连接远程服务器的问题的完整指南。处理连接SQL Server数据库的故障。

除了尝试Teo Chuen Wei Bryan建议的所有方法外,还要确保在连接字符串中引用了正确的服务器/实例名称。

如果您在数据库服务器或web上使用主机名/实例的简写形式。配置文件,确保您使用完全限定域名(FQDN)/实例

此外,要从不存在SQL server客户端的服务器测试连通性,

——>创建一个文本文件,并将其扩展名为。udl

右键单击文件,你可以看到连接选项卡。

——>输入服务器名和登录信息,测试连接到数据库服务器。

希望这能有所帮助。

当我想在另一台PC上运行我的WinForms项目(包括使用SQL Server数据库,并且在我的PC上工作得很好)时,我也犯了同样的错误。问题出在我电脑的Windows防火墙上。我通过添加两条规则来解决这个问题。这是如何允许SQL Server通过Windows防火墙的整个过程:

打开“运行”,输入services.msc 查找用于SQL Server(实例名)和SQL Server Browser的服务。一次一个,右键单击,选择“属性”,复制路径到exe文件 然后打开防火墙。cpl,单击允许应用程序或添加规则,添加之前复制的路径(有一个步骤需要遵循),选中域和私有,取消选中公共。

这是YouTube的链接,你可以看到这个过程:允许SQL Server通过Windows防火墙

我发现以下技巧很有用:

Make sure your database engine is configured to accept remote connections: Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration Click on Surface Area Configuration for Services and Connections Select the instance that is having a problem > Database Engine > Remote Connections Enable local and remote connections Restart instance You may need to create an exception on the firewall for the SQL Server instance and port you are using: Start > Run > Firewall.cpl Click on exceptions tab Add sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft SQL Server\MSSQL.x\MSSQL\Bin, check your installs for the actual folder path) and port (default is 1433) Check your connection string as well From FIX : ERROR : Could not open a connection to SQL Server: Check if your SQL server services is up and running properly: Go to All Programs > Microsoft SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services Check to make sure SQL Server service status is Running. In addition, ensure that your remote server is in the same network. Run sqlcmd -L to ascertain if your server is included in your network list. Enable TCP/IP in SQL Server Configuration When two or more SQL Servers are connected across network they do all communication using TCP/IP. The default port of SQL Server installation is 1433. This port can be changed through SQL Server Configuration Manager. TCP/IP should be enabled for SQL Server to be connected. Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP Right Click on TCP/IP >> Click on Enable You must restart SQL Server Services for all the changes to take effect. Right click and go to menu properties to select location where default port of SQL Server can be changed.