执行读取器等待操作超时错误



几天以来一直坚持这个问题,请帮忙。我已经尝试了很多解决方案,例如在 web 配置中增加连接超时:下面是我的错误代码。

    Server Error in '/' Application.
The wait operation timed out

说明:执行当前 Web 请求期间发生未经处理的异常。请查看堆栈跟踪,了解有关错误及其在代码中起源位置的详细信息。

Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out

源错误:

Line 595:        SqlCommand cmd = new SqlCommand(str, con);
Line 596:        con.Open();
Line 597:        rd = cmd.ExecuteReader();
Line 598:        //cs.CloseConnection();
Line 599:        return rd;
Source File: c:inetpubvhostsxyz.comhttpdocsApp_Codeadmin.cs    Line: 597 

堆栈跟踪:

[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1789294
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5340642
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
   System.Data.SqlClient.SqlDataReader.get_MetaData() +90
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +377
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +137
   System.Data.SqlClient.SqlCommand.ExecuteReader() +99
   admin.GetDatareader(String str) in c:inetpubvhostsYXZ.comhttpdocsApp_Codeadmin.cs:597
   subcategories.Page_Load(Object sender, EventArgs e) in c:inetpubvhostsXYZ.comhttpdocsshop.aspx.cs:440
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34274

尝试将 0 分配给命令超时,如下所示。值为 0 表示没有限制(尝试执行命令将无限期等待)。如果仍然超时,请优化存储过程。

    SqlCommand cmd = new SqlCommand(str, con);
    cmd.CommandTimeout = 0;
    con.Open();
    rd = cmd.ExecuteReader();

您可以按如下方式设置命令超时:

 SqlCommand cmd = new SqlCommand(str, con);
 cmd.CommandTimeout = 480;
 con.Open();
 rd = cmd.ExecuteReader();

注意:除了超时配置外,您还需要提高相关 SQL 的性能。

相关内容

  • 没有找到相关文章

最新更新