【发布时间】:2013-07-05 21:54:41
【问题描述】:
我们在一台机器上部署了一些应用程序,这些应用程序连接到远程安装的 MSSQL 2012 实例。除了一个应用程序,它们在本地管理员帐户下作为 Windows 服务运行。 客户端在 Windows 7 32 位上运行,数据库在 Windows Server 2008 R2 64 位上运行。
我在四分之一的连接尝试中收到此错误:
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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
bei System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
bei System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
bei System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
bei System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
bei System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
bei System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
bei System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
bei System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
bei System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
bei System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
bei System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
bei System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
bei System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
bei System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
bei System.Data.SqlClient.SqlConnection.Open()
我在所有应用程序中使用此连接字符串:
Data Source=192.168.0.101\NAMEDINSTANCE;Initial Catalog=database;Integrated Security=False;Persist Security Info=False;User ID=user;Password=password
我检查了无限 ping 请求的网络连接,但发生错误时没问题。 首先我收到了类似的错误消息,虽然启用了 NamedPipes,但是在停用 NamedPipes(我们没有使用它)之后,上述错误以相同的频率发生。 相同的设置正在其他机器上运行。 该错误在几周前开始发生,然后才成功运行了大约 3 个月。这是一个离线设置,系统自部署以来没有更新(但我不能保证)。 两台机器上的防火墙都关闭了。 Windows 和 SQL-Server 事件日志都没有提示。 我还更换了网络电缆以排除电缆断裂。
我现在有点卡住了,因为我不知道下一步该去哪里。也许有一些可用的连接字符串的调整,或者我可以更改一些配置服务器或客户端。
更新: 在 granadaCoders 的帮助下,我发现 tcp 调用可能会被某些东西过滤掉。我使用 PortQry 进行了检查。
portqry -n 192.168.0.101 -e 1433 -p tcp
TCP port 1433 (ms-sql-s service): FILTERED
如果这种情况一直发生,我会说防火墙阻止了我的呼叫,但在这种情况下,可能是某种系统过载导致失去我的请求。 接下来要做的事情肯定是通过连接特定端口来检查它是否是 SQL Server Browser 故障。然后更换开关。
更新 (2013-07-03): 我编写了一个测试应用程序,它每秒打开一个连接并在故障系统上运行它。有效。我在几个连接中两次在其他应用程序上遇到错误,但在我的测试应用程序中的 500 个连接内没有设法获得一次。
更新(2013-07-05:我忘记了此服务器还有另一个网络连接。该连接是几周前连接的。看起来这是此问题的根本原因。
【问题讨论】:
-
你为什么要在这上面标记 C#??
-
但是你谈论的只是网络、SQL Server 和策略,所以除非是特定的 C# 问题,否则请不要标记 C#
-
@JoelCoehoorn 不太可能,这几乎可以肯定是网络配置或集群服务器问题。不太可能需要更改 C# 代码,甚至是 SQL Server 实例本身。他们最多可能需要更改连接字符串。但是我已经看到这种事情数千次了,90% 的时间是网络上的某些东西阻塞连接的问题,另外 10% 的问题通常是集群/场能够正确地为请求提供服务的问题.
-
你可能知道,但 OP 可能不知道。是的,在确认它确实不是 C# 问题后,重新标记问题,但不要对 OP 标记错误感到愤怒。排除故障的首要规则之一是不要忽视任何可能导致问题的因素。
-
我再次删除了 C# 标签,因为它会将答案引向错误的方向。关于如何正确建立 sql 连接的答案可能会解决类似的问题,但不是我在这里寻找的。span>
标签: sql-server