.net SQL 连接错误:System.Data.SqlClient.SqlException (0x80131904)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26135346/
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
SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904)
提问by Sean Borner
I am seeing this in several situations and it is intermittent in our web based application connecting to SQL 2008 R2 serve back end. Users are coming across a point 2 point connection and seeing this on and off. Thought it was bandwidth issues until I started seeing it on terminal servers that are on the same core switch as this SQL server. I have checked remote connection enabled, Port 1433 is set correctly in Configuration for TCP/IP and the only thing I see that could be a cause is the timeout setting is set to 100000 in the remote connections rather than unlimited.
我在几种情况下都看到了这种情况,并且在我们基于 Web 的应用程序连接到 SQL 2008 R2 服务后端时它是间歇性的。用户遇到点 2 点连接并看到它时断时续。一直以为是带宽问题,直到我开始在与此 SQL 服务器位于同一核心交换机上的终端服务器上看到它。我检查了远程连接已启用,在 TCP/IP 的配置中正确设置了端口 1433,我看到的唯一可能是原因是远程连接中的超时设置设置为 100000 而不是无限。
The error is
错误是
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)--->
System.ComponentModel.Win32Exception(0x80004005): The network path was not foundatSystem.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.b__0() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.Core.EntityClient.EntityConnection.Open() ClientConnectionId:00000000-0000-0000-0000-000000000000
System.Data.SqlClient.SqlException(0x80131904):与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)--->
System.ComponentModel.Win32Exception(0x80004005):未找到网络路径atSystem.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.b__0() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.Core.EntityClient.EntityConnection.Open() ClientConnectionId:00000000-0000-0000-0000-000000000000
回答by Spider man
i had the same issue. go to Sql Server Configuration management->SQL Server network config->protocols for 'servername' and check named pipes is enabled.
我遇到过同样的问题。转到 Sql Server 配置管理-> SQL Server 网络配置-> 'servername' 的协议并检查命名管道是否已启用。
回答by Vijay Dodamani
I had the same issue.
我遇到过同样的问题。
Make sure that In SQL Server configuration --> SQL Server Services --> SQL Server Agent is enable
确保在 SQL Server 配置中 --> SQL Server 服务 --> SQL Server 代理已启用
This solved my problem
这解决了我的问题
回答by Srivathsa Harish Venkataramana
Anyone who has this error, especially on Azure, try adding "tcp:" to the db-server-name in your connection string in your application. This forces the sql client to communicate with the db using tcp. I'm assuming the connection is UDP by default and there can be intermittent connection issues
任何遇到此错误的人,尤其是在 Azure 上,请尝试将“tcp:”添加到应用程序连接字符串中的 db-server-name。这会强制 sql 客户端使用 tcp 与数据库通信。我假设默认情况下连接是 UDP 并且可能存在间歇性连接问题
回答by Chethan
Check these steps.
检查这些步骤。
- go to Sql Server Configuration management->SQL Server network config->protocols for 'servername' and check TCP/IP is enabled.
- Open SSMS in run, and check you are able to login to server using specfied username/password and/or using windows authentication.
- repeat step 1 for SQL native client config also
- 转到 Sql Server 配置管理->SQL Server 网络配置-> 'servername' 的协议并检查 TCP/IP 是否已启用。
- 在运行中打开 SSMS,并检查您是否能够使用指定的用户名/密码和/或使用 Windows 身份验证登录到服务器。
- 对 SQL 本机客户端配置也重复步骤 1
回答by Jason Soderberg
Check you routes, the update on 9/28/2014 impacted us. We had to adjust our older servers and add new routes. Here is the article http://www.rackspace.com/knowledge_center/article/updating-servicenet-routes-on-cloud-servers-created-before-june-3-2013
检查您的路线,2014 年 9 月 28 日的更新影响了我们。我们不得不调整旧服务器并添加新路由。这是文章http://www.rackspace.com/knowledge_center/article/updating-servicenet-routes-on-cloud-servers-created-before-june-3-2013
回答by lmoglia
See my post here
在这里看到我的帖子
How are you? I had the same problem while i was trying connect to MSSQL Server remotely using jdbc (dbeaver on debian).
After a while, i found out that my firewall configuration was not correctly. So maybe it could help you!
Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service.
Four exceptions must be configured in Windows Firewall to allow access to SQL Server:
A port exception for TCP Port 1433. In the New Inbound Rule Wizard dialog, use the following information to create a port exception: Select Port Select TCP and specify port 1433 Allow the connection Choose all three profiles (Domain, Private & Public) Name the rule “SQL – TCP 1433″ A port exception for UDP Port 1434. Click New Rule again and use the following information to create another port exception: Select Port Select UDP and specify port 1434 Allow the connection Choose all three profiles (Domain, Private & Public) Name the rule “SQL – UDP 1434 A program exception for sqlservr.exe. Click New Rule again and use the following information to create a program exception: Select Program Click Browse to select ‘sqlservr.exe' at this location: [C:\Program Files\Microsoft SQL Server\MSSQL11.\MSSQL\Binn\sqlservr.exe] where is the name of your SQL instance. Allow the connection Choose all three profiles (Domain, Private & Public) Name the rule SQL – sqlservr.exe A program exception for sqlbrowser.exe Click New Rule again and use the following information to create another program exception: Select Program Click Browse to select sqlbrowser.exe at this location: [C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]. Allow the connection Choose all three profiles (Domain, Private & Public) Name the rule SQL - sqlbrowser.exe
Source: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
你好吗?我在尝试使用 jdbc(debian 上的 dbeaver)远程连接到 MSSQL Server 时遇到了同样的问题。
过了一会儿,我发现我的防火墙配置不正确。所以也许它可以帮助你!
配置防火墙以允许与 SQL Server 和 SQL Server Browser 服务相关的网络流量。
必须在 Windows 防火墙中配置四个例外以允许访问 SQL Server:
TCP 端口 1433 的端口例外。在“新建入站规则向导”对话框中,使用以下信息创建端口例外: 选择端口 选择 TCP 并指定端口 1433 允许连接 选择所有三个配置文件(域、专用和公用)规则“SQL – TCP 1433” UDP 端口 1434 的端口例外。再次单击新建规则并使用以下信息创建另一个端口例外: 选择端口 选择 UDP 并指定端口 1434 允许连接 选择所有三个配置文件(域、专用和公共)将规则命名为“SQL – UDP 1434 sqlservr.exe 的程序异常。再次单击“新建规则”并使用以下信息创建程序异常: 选择程序 单击“浏览”以在以下位置选择“sqlservr.exe”:[C:\Program Files\Microsoft SQL Server\MSSQL11.exe。\MSSQL\Binn\sqlservr.exe] 其中是 SQL 实例的名称。允许连接 选择所有三个配置文件(域、私有和公共) 将规则命名为 SQL – sqlservr.exe sqlbrowser.exe 的程序例外 再次单击新建规则并使用以下信息创建另一个程序例外: 选择程序 单击浏览选择sqlbrowser.exe 位于此位置:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 命名规则 SQL - sqlbrowser.exe exe 再次单击“新建规则”并使用以下信息创建另一个程序异常: 选择程序 单击“浏览”以在此位置选择 sqlbrowser.exe:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 命名规则 SQL - sqlbrowser.exe exe 再次单击“新建规则”并使用以下信息创建另一个程序异常: 选择程序 单击“浏览”以在此位置选择 sqlbrowser.exe:[C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe]。允许连接 选择所有三个配置文件(域、私有和公共) 命名规则 SQL - sqlbrowser.exe
来源:http: //blog.citrix24.com/configure-sql-express-to-accept-remote-connections/

