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

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

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

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


当前回答

在我的情况下,MSSQLSERVER服务有一个问题,所以我重新启动服务,问题解决了。

所以我建议通过Windows键进入服务应用程序,搜索“服务”,然后找到你的Sql实例,通常是“Sql Server (MSSQLSERVER)”在Microsoft Sql Server。 右键单击服务,然后单击启动,如果禁用,则单击重新启动。

其他回答

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

azure vm用户

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

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

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

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

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

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

我使用的是SQL Server 2016和windows 10。

首先是允许远程连接到SQL Server。 我所做的就是键入sqlservermanager13。在开始菜单打开SQL Server配置管理器。确保TCP/IP状态为启用状态。

双击TCP/IP协议名称,检查TCP端口号。通常默认值是1433。

以下步骤通过使用Microsoft管理控制台(MMC)管理单元配置Windows防火墙的高级安全。高级安全Windows防火墙只配置当前配置文件。

To open a port in the Windows firewall for TCP access On the Start menu, click Run, type WF.msc, and then click OK. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane. In the Rule Type dialog box, select Port, and then click Next. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine, such as 1433 for the default instance. Click Next. In the Action dialog box, select Allow the connection, and then click Next. In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the Database Engine, and then click Next. In the Name dialog box, type a name and description for this rule, and then click Finish.

另一个需要配置的东西。

To open access to SQL Server when using dynamic ports On the Start menu, click Run, type WF.msc, and then click OK. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane. In the Rule Type dialog box, select Program, and then click Next. In the Program dialog box, select This program path. Click Browse, and navigate to the instance of SQL Server that you want to access through the firewall, and then click Open. By default, SQL Server is at C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Binn\Sqlservr.exe. Click Next. In the Action dialog box, select Allow the connection, and then click Next. In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the Database Engine, and then click Next. In the Name dialog box, type a name and description for this rule, and then click Finish.

看看微软的文档 配置Windows防火墙访问数据库引擎

我尝试了关于这个问题的所有其他答案,其中一些(如果不是全部的话)可能在让这个为我工作方面发挥了作用,但我仍然无法远程连接到DB。我在Azure虚拟机上使用SQL Server。

我最终想起了VM的端点是由Azure帐户代理控制的,所以我继续使用Azure Portal并添加1433作为可用端点,这样我就可以连接到我的SQL实例了。

希望这能帮助那些尝试了所有其他答案但仍然没有运气的人!

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