最近我发现从我们的一个网络服务器到 MSSQL AlwaysOn 侦听器的连接失败了。侦听器有两个 IP 地址,因为它跨越子网,因此我们在连接字符串中指定 Multisubnetfailover=true。
尝试与侦听器建立连接时,出现以下错误:
System.Data.SqlClient.SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while
attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake
failed or the server was unable to respond back in time. The duration spent while attempting to connect to this
server was - [Pre-Login] initialization=20991; handshake=0; ---> System.ComponentModel.Win32Exception
(0x80004005): The wait operation timed out 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 IRNXMLGateway.Controllers.IRNXMLGatewayController.GenericCall(String methodCall) in
CODELINE:line 376
ClientConnectionId:92074b33-176a-4006-b7c7-892e01a3eea7
我也尝试使用 SSMS 连接并遇到相同的超时问题。
我能够通过以下方式成功建立连接:
- 无需监听器直接连接到主机
- 直接连接到当前监听 IP 地址
- 将连接超时增加到 200 秒
- 删除连接字符串中的 MultiSubnetFailover 选项
尝试从其他服务器连接时,我没有遇到此问题。SQL 或 Windows 事件日志中没有错误,可帮助确定超时的原因。网络跟踪显示与当前侦听器 IP 地址的正确连接握手。两台服务器都没有启用防火墙或防病毒软件。Webserver 运行 server 2008 web edition,SQL server 运行 windows server 2012 和 sql server 2012。