【问题标题】:How to prevent the application from Timeout expired Exception?如何防止应用程序出现 Timeout expired Exception?
【发布时间】:2016-10-03 16:43:18
【问题描述】:

请帮助从 Stack Strace 下方找出异常原因:

Error=Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding., 

StackTrace = 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.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Core.ResService.DataAccess.SQLHelper.ExecuteNonQuery(SqlConnection conn, SqlTransaction trans, CommandType cmdType, String cmdText, SqlParameter[] cmdParms)
   at Core.ResService.DataAccess.ReservationDal.SelectActiveResXml(Int32 resvID, String sessionID)
   at Core.ResService.BusinessLogic.Reservation.SelectActiveReservation(Int32 hotelID, Int32 resvID, String sessionID) 

关于上述异常堆栈跟踪的任何想法,如可能的解决方案和原因将被告知。

【问题讨论】:

  • 默认情况下,您从应用程序中创建的 SQL 连接将在 30 秒后超时。如果您的查询花费的时间比这更长,您将得到一个异常。要么对查询进行一些性能调整(添加索引检查 where 子句等),要么在代码中增加连接超时。

标签: c# .net timeoutexception


【解决方案1】:

它会在堆栈跟踪中告诉您。您的 SQL 调用超时。修复 SQL 调用或增加超时。命令对象有一个 timeout 属性,但你真的应该修复你的 SQL。

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2022-07-27
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    相关资源
    最近更新 更多