【问题标题】:SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904)SQL 连接错误:System.Data.SqlClient.SqlException (0x80131904)
【发布时间】:2014-11-25 22:31:12
【问题描述】:

我在几种情况下都看到了这种情况,并且在我们连接到 SQL 2008 R2 服务后端的基于 Web 的应用程序中它是断断续续的。用户遇到点 2 点连接并看到此连接打开和关闭。一直以为是带宽问题,直到我开始在与此 SQL 服务器位于同一核心交换机上的终端服务器上看到它。我已经检查了远程连接是否启用,端口 1433 在 TCP/IP 配置中设置正确,我看到的唯一原因是远程连接中的超时设置设置为 100000,而不是无限制。

错误是

System.Data.SqlClient.SqlException (0x80131904): 网络相关或 建立连接时发生特定于实例的错误 SQL 服务器。服务器未找到或无法访问。核实 实例名称正确且 SQL Server 配置为 允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接) --->

System.ComponentModel.Win32Exception (0x80004005): 网络路径 没找到at

System.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

【问题讨论】:

  • 这通常意味着您有网络问题。我会先咨询你的网络工程师(假设你有一个)。
  • 我怀疑这是一个配置问题,否则你不会是seeing this on and off
  • 可能会有所帮助:blogs.msdn.com/b/sql_protocols/archive/2007/03/31/… 是否也通过重新启动服务器(暂时)好转?如果是这样,technet.microsoft.com/en-us/library/ms187030(v=sql.105).aspx 允许的最大用户连接数是多少?
  • 仅供参考:0x80131904 并非特定于此 Sql 错误。你也得到了其他 SqlExceptions(例如,不能在对象中插入重复的键行..)
  • 检查 SQL Server 配置管理器以确保您已启用所有需要的客户端协议。就我而言,我需要启用 TCP/IP..

标签: .net sql-server sql-server-2008 named-pipes


【解决方案1】:

检查这些步骤。

  1. 转到 Sql Server 配置管理->SQL Server 网络配置->'servername' 的协议并检查 TCP/IP 是否已启用。
  2. 在运行中打开 SSMS,并检查您是否能够使用指定的用户名/密码和/或使用 Windows 身份验证登录到服务器。
  3. 对 SQL 本地客户端配置也重复第 1 步

【讨论】:

    【解决方案2】:

    检查您的路线,2014 年 9 月 28 日的更新影响了我们。我们不得不调整旧服务器并添加新路线。这里是文章http://www.rackspace.com/knowledge_center/article/updating-servicenet-routes-on-cloud-servers-created-before-june-3-2013

    【讨论】:

      【解决方案3】:

      看我的帖子here

      你好吗?我在尝试连接时遇到了同样的问题 MSSQL Server 远程使用 jdbc(debian 上的 dbeaver)。

      过了一会儿,我发现我的防火墙配置没有 正确。所以也许它可以帮助你!

      将防火墙配置为允许与 SQL 相关的网络流量 服务器和 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 服务器\MSSQL11.\MSSQL\Binn\sqlservr.exe] 其中 是您的 SQL 实例的名称。允许 连接选择所有三个配置文件(域、私有和公共)名称 规则 SQL – sqlservr.exe sqlbrowser.exe 的程序异常 再次单击 New Rule 并使用以下信息创建 另一个程序例外:选择程序单击浏览以选择 此位置的 sqlbrowser.exe:[C:\Program Files\Microsoft SQL 服务器\90\Shared\sqlbrowser.exe]。允许连接 全选 三个配置文件(域、私有和公共)将规则命名为 SQL - sqlbrowser.exe

      来源: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/

      【讨论】:

        【解决方案4】:

        我有同样的问题。 转到 Sql Server 配置管理->SQL Server 网络配置->'servername' 的协议并检查命名管道是否已启用。

        【讨论】:

        • 命名管道?你有令牌环网络吗?还有时间机器?
        • @cdonner 你没听说过命名管道吗?我已经解释了当我遇到同样的错误时我做了什么。
        • 真正的错误是权限相关,我可以在 Windows 操作系统头文件中看到:0x80004005
        【解决方案5】:

        我遇到了同样的问题。

        确保在 SQL Server 配置中 --> SQL Server 服务 --> SQL Server 代理已启用

        这解决了我的问题

        【讨论】:

        • 如何进入 SQL Server 配置页面?我试过但无法访问它。
        【解决方案6】:

        任何遇到此错误的人,尤其是在 Azure 上,尝试将“tcp:”添加到应用程序连接字符串中的 db-server-name 中。这会强制 sql 客户端使用 tcp 与 db 进行通信。我假设默认情况下连接是 UDP,并且可能存在间歇性连接问题

        【讨论】:

          【解决方案7】:

          我遇到了同样的异常,它抛出类似“无法打开数据库'YYYY'的消息。它正在恢复中。”这是我的预期行为,sql server 实际上正在恢复。

          错误号是927。有关所有错误编号,请参阅 https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc645603(v=sql.105)?redirectedfrom=MSDN

          如何捕捉此类 sql 异常:

          try
          {
              await db.ExecuteProcAsync(...);
          }
          catch (SqlException e) when (e.Number == 927)
          {
              ...
          }
          

          【讨论】:

          • 不错的一个。基于这个想法,可以构建一个处理程序来生成用户友好的错误消息。链接中的错误编号列表非常全面且有用。谢谢。
          【解决方案8】:

          我曾多次遇到同样的问题。答案是,使用“::1”或“127.0.0.1”而不是“localhost”。我们经常使用 ssh-tunnels 连接远程数据库。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2018-05-30
            • 1970-01-01
            • 2014-03-19
            • 2016-04-22
            • 2018-08-15
            • 2015-06-06
            • 1970-01-01
            相关资源
            最近更新 更多