c# - ExecuteReader等待操作超时错误

标签 c# sql asp.net .net executereader

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

    Server Error in '/' Application.

The wait operation timed out

描述:当前网络请求执行过程中出现未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

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:\inetpub\vhosts\xyz.com\httpdocs\App_Code\admin.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:\inetpub\vhosts\YXZ.com\httpdocs\App_Code\admin.cs:597
   subcategories.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\XYZ.com\httpdocs\shop.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();

关于c# - ExecuteReader等待操作超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35549967/

相关文章:

c# - 测试对象是否为任何泛型类型实现了泛型接口(interface)

java - 如何不将数据字段发送到数据库 Java 和 Microsoft Access

sql - 提高 PostgresQL 聚合查询性能

MySQL同一表的子行的递归更新

c# - 运行示例 MVC 项目时需要身份验证

C# 从数组集合中删除 "partial"重复项

c# - 枚举程序集中的命名空间

c# - 'context' 在 C# async/await 代码中到底意味着什么?

c# - 菜单中的连接不起作用

javascript - 使用 jQuery 在 ASP.NET 中使用模态表单