.net 为什么在与 SQL Server 建立连接时会出现与网络相关或特定于实例的错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1391503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why did a network-related or instance-specific error occur while establishing a connection to SQL Server?
提问by Jean-Fran?ois C?té
I'm very frustrated. I have a website running on Visual Web Developer 2008 Express with my local database, everything works great. I also have the same web site running on a production server. Everything was working great but tonight I did a "reset" on production.
我很沮丧。我有一个使用本地数据库在 Visual Web Developer 2008 Express 上运行的网站,一切正常。我也在生产服务器上运行相同的网站。一切都很好,但今晚我对生产进行了“重置”。
I deleted a couple of table, re-created them and inserted data. Everything was ok at this time.
I deleted ALL the files via the FTP.
I used the module called "Copy website" in visual studio and copy the site to the website via FTP.
我删除了几个表,重新创建它们并插入数据。此时一切正常。
我通过FTP删除了所有文件。
我在visual studio中使用了名为“复制网站”的模块,并通过FTP将网站复制到网站。
When I log on my website, here is the error I got:
当我登录我的网站时,这是我得到的错误:
Server Error in '/' Application.
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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: 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)
“/”应用程序中的服务器错误。
与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)
Nothing has changed related to SQL connection, this is OLD code that I always used. My website is completely paralysed because of this and I feel sick inside because I feel there is nothing I can do.
SQL 连接没有任何变化,这是我一直使用的旧代码。我的网站因此完全瘫痪,我内心感到恶心,因为我觉得我无能为力。
Can anyone help me please?
有人可以帮我吗?
采纳答案by Johannes Rudolph
Your connection string was probably overriden when you copied your new website version on the server. Please check the connection string in web.config and see if it is valid.
当您在服务器上复制新网站版本时,您的连接字符串可能已被覆盖。请检查 web.config 中的连接字符串,看看它是否有效。
回答by MacGyver
If you are connecting from Windows Machine A to Windows Machine B (server with SQL Server installed) and are getting this error, you need to do the following:
如果您从 Windows 机器 A 连接到 Windows 机器 B(安装了 SQL Server 的服务器)并收到此错误,您需要执行以下操作:
On Machine B:
在机器 B 上:
回答by Jayesh Amarnani
I've resolved the issue. It was due to the SQL browser service.
我已经解决了这个问题。这是由于 SQL 浏览器服务。
Solution to such problem is one among below -
此类问题的解决方案是以下之一 -
Check the spelling of the SQL Server instance name that is specified in the connection string.
Use the SQL Server Surface Area Configuration tool to enable SQL Server to accept remote connections over the TCP or named pipes protocols. For more information about the SQL Server Surface Area Configuration Tool, see Surface Area Configuration for Services and Connections.
Make sure that you have configured the firewall on the server instance of SQL Server to open ports for SQL Server and the SQL Server Browser port (UDP 1434).
Make sure that the SQL Server Browser service is started on the server.
检查连接字符串中指定的 SQL Server 实例名称的拼写。
使用 SQL Server Surface Area Configuration 工具使 SQL Server 能够接受通过 TCP 或命名管道协议的远程连接。有关 SQL Server 表面区域配置工具的详细信息,请参阅服务和连接的表面区域配置。
确保已将 SQL Server 服务器实例上的防火墙配置为打开 SQL Server 端口和 SQL Server Browser 端口 (UDP 1434)。
确保在服务器上启动了 SQL Server Browser 服务。
回答by Brajendu Kumar Das
check forthe followings :
检查以下内容:
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
? 开始 > 所有程序 > SQL Server 2005 > 配置工具 > SQL Server Surface Area 配置?单击服务和连接的表面积配置?选择有问题的实例 > 数据库引擎 > 远程连接?启用本地和远程连接 ? 重启实例
- Check the SQL Server service account
- 检查 SQL Server 服务帐户
? If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding
? 如果您不使用域帐户作为服务帐户(例如,如果您使用的是 NETWORK SERVICE),您可能希望在继续之前先切换它
- If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
- 如果您使用的是命名的 SQL Server 实例,请确保在 ASweb P.NET 应用程序的连接字符串中使用该实例名称
? Usually the format needed to specify the database server is machinename\instancename ? Check your connection string as well
? 通常指定数据库服务器所需的格式是 machinename\instancename ?还要检查您的连接字符串
回答by Agasani
If your server was working and suddenly started erroring out, your server/instance stopped and connection settings were changed somehow.
如果您的服务器正在工作并突然开始出错,则您的服务器/实例停止并且连接设置以某种方式更改。
For SQL Server 2008 here is how you can fit this:
对于 SQL Server 2008,您可以通过以下方式进行调整:
- Goto
Start > All Programs > SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services.
And here you'll see all the instances and their state. - The state of the instance you were trying to connect can be stopped here.
- Double click on the instance and then click on connect.
- It will connect and now go back and run your application, you will be able to connect with no error.
- 转到
Start > All Programs > SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services。
在这里您将看到所有实例及其状态。 - 您尝试连接的实例的状态可以在此处停止。
- 双击实例,然后单击连接。
- 它将连接,现在返回并运行您的应用程序,您将能够毫无错误地连接。
This solution assumes the error is not being caused by something wrong in your connection string.
此解决方案假定错误不是由连接字符串中的错误引起的。
回答by Safraz
I had the same problem with SQL Server 2008 R2 and when I checked "SQL Server Configuration Manager" My SQL Server instance had Stopped. Right Clicking and Starting the Instance solved the issue.
我在使用 SQL Server 2008 R2 时遇到了同样的问题,当我检查“SQL Server 配置管理器”时,我的 SQL Server 实例已停止。右键单击并启动实例解决了这个问题。
回答by André Abboud
回答by Bhaskarreddy Mule
we have to enable TCP/IP property in sql server configuration manager
我们必须在sql server 配置管理器中启用 TCP/IP 属性
回答by mack28
I had same problem regarding that i.e A network-related or instance-specific error occurred while establishing a connection to SQL Server.
我遇到了同样的问题,即在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。
I was using SQL Server 2005 (.\sqlexpress)`and worked fine but suddenly services stopped and gave me error.
我正在使用SQL Server 2005 (.\sqlexpress)`并且工作正常但突然服务停止并给我错误。
I solved it like this,
我是这样解决的
Start -> Search Box - > Sql Configuration Manager -> SQL Server 2005 Services >and just Change Your SQL Server (SQLEXPRESS) Stateto Running by right clicking that service Sate.
开始 -> 搜索框 -> Sql 配置管理器 -> SQL Server 2005 服务 > 并通过右键单击该服务状态将SQL Server (SQLEXPRESS) 状态更改为运行。
回答by Jeff Johnson
I recently had this problem and it ended up being a port issue. My production SQL Server was set up at to be port 1427 instead 1433.
我最近遇到了这个问题,结果是端口问题。我的生产 SQL Server 设置为端口 1427 而不是 1433。
Just change the connection string to be
只需将连接字符串更改为
...data source=MySQLServerName,1427;initial catalog=MyDBName...
Hope this helps anyone who might be seeing this same issue.
希望这可以帮助任何可能遇到相同问题的人。


