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

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

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

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


当前回答

总结

要修复在运行本地应用程序与远程数据库时遇到的此问题,请使用SQL Server配置管理器为远程数据库添加别名。

细节

I had run into this problem recently when transitioning from a Windows 7 to a Windows 10 laptop. I was running a local development and runtime environment accessing our Dev database on a remote server. We access the Dev database through a server alias setup through SQL Server Client Network Utility (cliconfg.exe). After confirming that the alias was correctly setup in both the 64 and 32 bit versions of the utility and that the database server was accessible from the new laptop via SSMS, I still got the error seen by the OP (not the OP's IP address, of course).

有必要使用SQL Server Configuration Manager为远程Dev数据库服务器添加别名。把事情都解决了。

其他回答

我几乎什么都试过了。然后,我已经卸载了Malwarebytes。一种声称可以删除恶意软件的软件(通常可以)。在那之后,一切都好了。也许有人会因为同样的原因遇到同样的问题。

似乎您的localdb实例没有运行。 要在计算机启动时启动它,添加到您的开始菜单\启动文件夹BAT文件与以下行

sqllocaldb start name_of_instance

其中name_of_instance是要启动的localdb实例的名称。 您可以使用sqllocaldb i在命令行中列出可用的实例。

例如,如果您正在使用SQL Server Management Studio并连接到服务器名称(localdb)\v11.0,那么您的BAT文件将如下所示

sqllocaldb start v11.0

如果以上解决方案都不起作用(对我来说都不起作用),那么只需重新启动计算机,您就可以连接到sql server (localhost)。

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

如果SQL Server正在运行,您仍然得到一个错误; 当打开SQL Server时,显示的不是默认的服务器名 选项下选择以\SQLEXPRESS结尾的服务器名 服务器名称->浏览更多信息->数据库引擎选项。