Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何防止应用程序超时过期异常?_C#_.net_Timeoutexception - Fatal编程技术网

C# 如何防止应用程序超时过期异常?

C# 如何防止应用程序超时过期异常?,c#,.net,timeoutexception,C#,.net,Timeoutexception,请从下面的堆栈策略帮助确定异常原因: 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

请从下面的堆栈策略帮助确定异常原因:

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调用超时。修复SQL调用或增加超时。command对象上有一个timeout属性,但您确实应该修复SQL。

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