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

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

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

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


当前回答

按window + R(运行窗口打开),在运行窗口类型“服务”。msc”和新服务打开找到实例名SQL SERVER在我的情况下,它是SQL SERVER(SQLEXPRESS),然后启动这个服务,再试一次,它为我工作,希望它也为你工作。

其他回答

虽然以上的解决方案应该在90%的情况下工作,但如果你还在阅读这个答案!!您可能正在尝试连接到与预期不同的服务器。这可能是由于配置文件指向不同的SQL服务器,而不是您认为要连接的实际服务器。

至少在我身上发生过。

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

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

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

我发现以下技巧很有用:

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.

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

我的问题开始于我试图将服务器从IIS Express更改为本地IIS(同时使用LocalDB)。

我正在使用LocalDB(用于开发目的),当我从本地IIS恢复到IIS Express时,Visual Studio已经将我的数据源从数据源=(LocalDB)\MSSQLLocalDB切换到数据源=.\SQLEXPRESS

错误的连接字符串

< add name = " DefaultConnection connectionString =“源代码=数据。\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \ SurveyTestsDB。中密度纤维板;最初用户目录= SurveyTestsDB集成安全= True;例如= True” providerName =“系统数据。SqlClient " - >

正确的连接串

< add name = " DefaultConnection connectionString =“源代码=数据(LocalDb) \ MSSQLLocalDB; AttachDbFilename = | DataDirectory | \ SurveyTestsDB。中密度纤维板最初目录》中= SurveyTestsDB;集成安全= True”providerName =“系统数据。SqlClient " - >

希望这能帮助到一些人。