【发布时间】: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