备忘录-解决 (0x80131904): Timeout 时间已到的问题

时间:2025-03-05 17:47:09

这段时间写Android和IOS服务时 sql数据库查询有数据正常,没数据总是报异常: (0x80131904): Timeout 时间已到。在操作完成之前超时时间已过或服务器未响应。 ---> .Win32Exception (0x80004005): 等待的操作过时。
   在 (SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   在 (SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   在 (TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   在 (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   在 (_SqlMetaDataSet metaData, Boolean moreInfo)
   在 (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   在 ()
   在 .get_MetaData()
   在 (SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   在 (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   在 (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   在 (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   在 (CommandBehavior behavior, String method)
   在 (CommandBehavior behavior)
   在 (String _sConnectionString, CommandType _oCmdType, String _sCmdText, SqlParameter[] _oCommandParameters)
ClientConnectionId:bcab2341-64f4-4dae-92c4-6bfca904321b

但是把sql放到数据库执行在1秒以内 到服务端就会超时。做了个时间测试,数据库执行确实用了30秒,然后就超时了。

找了很多方案,最后在数据库执行一下命令就好了:

exec sp_updatestats;