Microsoft Azure > Web App -- SQL 连接被远程主机强行关闭 -- 仅在空闲时间后的第一次调用时发生
Microsoft Azure > Web App -- SQL Connection was forcibly closed by the remote host -- Happens only for the first call after idle time
这是在连接到 SQL MI 实例时在 MS Azure 应用程序设置中发生的。流量流经 HCM。
相同的代码适用于 Web 应用程序直接查询 SQL 服务器 201 的本地设置。
"This issue is reproducible if we keep the application idle for a few minutes and retrigger any request which has database interaction"。一旦记录了以下错误,后续请求就可以正常工作。
记录了以下错误:
Properties:
SqlException.Errors = {
"System.Data.SqlClient.SqlError: A connection was successfully established with the server, but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)",
}
SqlException.ClientConnectionId = "4560-9ca8-53ea0fdeca60"
SqlException.Class = "20"
SqlException.LineNumber = "0"
SqlException.Number = "10054"
SqlException.Procedure = ""
SqlException.Server =""
SqlException.State = "0"
SqlException.Source = ".Net SqlClient Data Provider"
SqlException.ErrorCode = "-2146232060"
Data:
HelpLink.ProdName = "Microsoft SQL Server"
HelpLink.EvtSrc = "MSSQLServer"
HelpLink.EvtID = "10054"
HelpLink.BaseHelpUrl = "http://go.microsoft.com/fwlink"
HelpLink.LinkId = "20476"
MS_LoggedBy = "System.Collections.Generic.List`1[System.Object]"
Stack Trace:
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
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)
我已经尝试使用 Internet、MSDN 上提供的文档,
一个。我开始详细记录 HCM 的 System.Net 日志。但是在套接字级别没有发现问题。事件查看器中记录了以下异常
HybridConnectionManager Trace: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
b。考虑到它可能是 tcp 连接断开,我尝试使连接池 =False。
c。验证连接是否正在处理。代码写在Using块中,已定义disposed。
我已经解决了这个问题。
这是由于连接断开。我们需要使用连接重试机制。
一种。使用企业库瞬态错误块
b.定义重试策略
C。将 ado.net 连接从 SqlConnection 更改为 ReliableSqlConnection
这是在连接到 SQL MI 实例时在 MS Azure 应用程序设置中发生的。流量流经 HCM。
相同的代码适用于 Web 应用程序直接查询 SQL 服务器 201 的本地设置。
"This issue is reproducible if we keep the application idle for a few minutes and retrigger any request which has database interaction"。一旦记录了以下错误,后续请求就可以正常工作。
记录了以下错误:
Properties:
SqlException.Errors = {
"System.Data.SqlClient.SqlError: A connection was successfully established with the server, but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)",
}
SqlException.ClientConnectionId = "4560-9ca8-53ea0fdeca60"
SqlException.Class = "20"
SqlException.LineNumber = "0"
SqlException.Number = "10054"
SqlException.Procedure = ""
SqlException.Server =""
SqlException.State = "0"
SqlException.Source = ".Net SqlClient Data Provider"
SqlException.ErrorCode = "-2146232060"
Data:
HelpLink.ProdName = "Microsoft SQL Server"
HelpLink.EvtSrc = "MSSQLServer"
HelpLink.EvtID = "10054"
HelpLink.BaseHelpUrl = "http://go.microsoft.com/fwlink"
HelpLink.LinkId = "20476"
MS_LoggedBy = "System.Collections.Generic.List`1[System.Object]"
Stack Trace:
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
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)
我已经尝试使用 Internet、MSDN 上提供的文档,
一个。我开始详细记录 HCM 的 System.Net 日志。但是在套接字级别没有发现问题。事件查看器中记录了以下异常
HybridConnectionManager Trace: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
b。考虑到它可能是 tcp 连接断开,我尝试使连接池 =False。
c。验证连接是否正在处理。代码写在Using块中,已定义disposed。
我已经解决了这个问题。 这是由于连接断开。我们需要使用连接重试机制。 一种。使用企业库瞬态错误块 b.定义重试策略 C。将 ado.net 连接从 SqlConnection 更改为 ReliableSqlConnection