System.Data.SqlClient.SqlException (0x80131904): Timeout exp



我已经开始遇到超时错误,但不确定如何处理它们,因为它们每次都不同。

第一个超时类型

System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception (258): Unknown error 258
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.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName, Boolean shouldReconnect)
at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName)
at System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.Common.DbConnection.BeginDbTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)

第二类超时

System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception (258): Unknown error 258
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

第三种超时类型

System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception (258): Unknown error 258
at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__126_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in C:projectsdapperDapperSqlMapper.Async.cs:line 419

我如何诊断这些问题?看哪里?为什么相同的超时错误发生在三个不同的操作?在客户端,CommandTimeout-setting是我最后的选择吗?

还有一个重要的细节:我在TEST环境中碰巧遇到了这个Timeout错误,即使不是在负载下。. net 6, MARS=false, Windows, Timeout=30。只有CommandTimeout为默认值。不幸的是,我没有设法捕捉到确切的堆栈跟踪。

p。看看搜索结果,似乎没有解决我的问题。在一种情况下,Timeout可能有助于[尝试-帮助消除连接超时]。在另一个-CommandTimeout[好吧,我可能尝试它,但键入它无处不在,我使用数据库?它也可以帮助BeginTransaction-timeouts吗?某些地方甚至存在MARS设置,但即使禁用MARS,问题也会重现。Linux或Windows -也没关系,因为在Windows上也会遇到问题。我们认为迁移到。net 6可能会有所帮助,但它也没有帮助。

链接到MSDN有人有同样的问题。我想相关的信息是:

消息本身就是无法到达实例时的标准消息。然而,错误258在这种情况下是不寻常的。这不是SQL Server错误,而是操作系统错误;. NET HELPMSG 258提示等待操作超时。

这可能表明你到达了某个地方,但实际上没有人在听。也就是说,端口是开放的,但是进程忙于其他事情。(这不是一个SQL Server进程)

那么,你的SQL Server怎么样了?无法跟上工作量?断断续续地死机吗?防病毒和/或网络保护软件?故障排除技巧

google sp_Blitz及其兄弟姐妹。它们是免费的脚本,可以帮助你发现SQL Server上的问题。还有sp_whoIsActive——它很擅长显示阻塞问题。

要发现线程池不足,最好的办法可能是等待统计。

检查sql server中的sys.dm_os_wait_statsDMV。选择它(并保存),等待一会儿,然后再次选择—等待状态是累积的,因此select * from sys.dm_os_wait_stats不会给您任何有用的信息。sp_Blitz可以帮助你完成这个任务。

如果你启用了查询存储,你可以很容易地找到最消耗资源的查询,但也有一些有用的等待统计细分-不确定线程池等待在哪里。

最新更新