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

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

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

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


当前回答

这个解决方案解决了SQL服务器背后的网络错误和服务问题

我在这里回答了一个类似的问题,您需要统计其他开放运行类型->服务。msc -在服务->排序停止你会看到一堆停止的SQL服务右键单击并启动

开始-有4个问题可能会导致常见的LocalDb SqlExpress Sql Server连接错误Sql网络接口,错误:50 -本地数据库运行时错误发生,在开始之前,您需要将v11或v12重命名为(LocalDb)\mssqllocaldb


Troubleshooting Steps

您没有正在运行的服务,执行命令net start MSSQLSERVER或net start MSSQL$ instancename 这里没有防火墙端口 配置 你的安装有问题/损坏(下面的步骤可以帮助你一个干净的开始) 您没有将V11或12重命名为mssqllocaldb/SqlServer

我发现最简单的是做下面的事情——我附上了图片和步骤以寻求帮助。


Resolution Steps:

首先验证您已经安装了哪个实例,您可以通过检查注册表并运行cmd来完成此操作

i .执行命令> Sqllocaldb.exe cmd> Sqllocaldb.exe s "那个versionyouwantfromlistbefore " 如果此步骤失败,可以使用选项d删除cmd> Sqllocaldb.exe d "someDb" cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb" cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"


重新启动MSSql服务器或简单地重新启动您的机器!

按住/按打开CMD,窗口+ R,输入“services.msc” 现在寻找sql server服务,打开查找带有实例名的sql server 然后重新启动此服务并重试

其他回答

我发现以下技巧很有用:

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.

我遇到了同样的问题,问题是我在解决方案(Weband Droid)中有几个项目,即使在包管理器控制台中选择了默认项目,它也使用了Droid项目的连接字符串:

PM> update-database -Verbose
Using StartUp project 'Droid'. <-- DROID
Using NuGet project 'Web'. <-- WEB
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
<!-- BAD TARGET DATABASE -->
Target database is: 'DefaultConnection' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
   [REMOVED TEXT]
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1,State:0,Class:20
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

在包管理器控制台设置启动项目到Web和默认项目后,我得到了它的工作。

在做了上面提到的所有事情之后: http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/ 对我来说还是没用。

以下步骤对我很有效:

开始>执行> cmd > sqlcmd -L

它将提示您服务器名。确保此服务器名称与SQL management studio的CONNECT to server框中试图连接的服务器名称相同。

我犯了这个愚蠢的错误,我一直使用MSSQLSERVER而不是使用这个服务器名。

希望这对像我一样犯愚蠢错误的人有所帮助。

谢谢。

我有自己的解决方案:

打开“SQL Server配置管理器” 现在点击“SQL Server网络配置”,然后点击“协议名称” 右键单击“TCP/IP”(确保它是启用的)单击属性 现在选择“IP地址”选项卡-转到最后一个条目“IP所有” 输入“TCP端口”1433。 现在重新启动“SQL Server . name .”使用“服务”。(winKey + r)

它会起作用……

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