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

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

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

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


当前回答

我也遇到过同样的问题 就我而言,我用这种方法解决了问题

步骤1:从开始菜单进入SQL server配置管理器

步骤2:启用TCP/IP

步骤3:双击TCP/IP,进入IP地址最后一个条目IP ALL,输入TCP端口1433然后应用

第四步:然后按win+r,写服务。msc打开服务,然后向下滚动,然后右键单击SQL Server (MSSQLSERVER)选择重新启动

这解决了我的问题。 即使做以上所有步骤都不能解决问题,然后简单地重新启动PC,希望它会工作。

其他回答

您可以测试以下方法。

a Check the connection string of the project. b Go to services and restart SQLServer Instance. c Open 'SQLServer Configuration Manager' In the left panel select 'SQLServer Network Configuration' and expanding it Select 'Protocols for MSSQLServer' In the right panel dbl click on 'TCP/IP' In the 'Protocol' tab set the 'Enabled' to 'Yes' In the 'IP Addresses' tab scroll to down In the 'IPAll' set 'TCP Port' to 1433 d Open 'Firewall with advanced security' In the right tab select 'Inbound Rules'

在中间选项卡找到“本地端口”是1433的记录,如果你找不到它,尝试用以下级别创建它

In the Start menu, click Run, type 'WF.msc', and then click OK In the left panel click the 'Windows Firewall with Advanced Security' In the right panel right-click 'Inbound Rules', and then click 'New Rule' In the Rule Type dialog box, select 'Port', and then click Next In the Protocol and Ports dialog box, select 'TCP', and select 'Specific Local Ports', and then type the port number 1433, Click Next In the Action dialog box, select Allow the connection, and then click Next In the 'Profile' dialog box, checking the Domain, Private and Public, Then click Next In the 'Name' dialog box, type 'SQL 1433 Port' and for a description write description for own. Then click Finish

Then in the middle tab double click the found item(Instance) or created item of 'SQL 1433 Port' name by you. Select 'Scope' tab in opened dialog box(SQL Server Properties) In the Local PC Go to google.com in your Browser and search 'My IP'. then copy of your 'IP' Go to the remote server and in the 'SQL Server Properties' dialog box of 'Scope' tab, in the 'Remote IP Address' select the 'These IP Addresses' option and click 'Add' button In the opened dialog box(IP Address) select 'This IP Address or Subnet' option and paste your 'IP', click OK button.

尝试在连接字符串的末尾添加一个和一个端口号(如1433)。

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

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

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

azure vm用户

我已经尝试了上面所有的(所以这些仍然可能是有效的),但仍然没有wotk。

重要提示:我的只是一个游乐场服务器,所以安全性真的不是问题。所以你要做好调查,这只是一种变通方法,不是安全的方法。

确保可以ping通服务器。在我的情况下,我可以RDP,但不能ping我的服务器在Azure上。我的请求总是超时。因为似乎Azure默认阻止ICMP协议。

您可以在防火墙中添加规则。在我的例子中,无论我在那台机器上通过防火墙添加了什么,都没有任何改变。感谢@John的上述回答,这也提醒了我,我必须从Azure门户上的网络添加这个。

只要我为端口0添加了规则,我就可以远程连接了。

这个链接这个链接也很有用。

我发现以下技巧很有用:

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.