Execute Reader wait operation time out error

1

stuck on this since few days please help. I have tried a lot of solutions like increase connection timeout in web config: below is my error code.

    Server Error in '/' Application.

The wait operation timed out

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

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 

Stack Trace:

[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
c#
sql
asp.net
.net
executereader
asked on Stack Overflow Feb 22, 2016 by Jayesh Patel

2 Answers

1

Try by assigning 0 to the command timeout as below. A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely). If its still timing out, optimize the stored procedure.

    SqlCommand cmd = new SqlCommand(str, con);
    cmd.CommandTimeout = 0;
    con.Open();
    rd = cmd.ExecuteReader();
answered on Stack Overflow Feb 23, 2016 by Praveena
0

You can set command timeout as below:

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

Note: along with timeout configuration, you also need to improve the performance of related SQL.

answered on Stack Overflow Feb 22, 2016 by HiteshAjudiya

User contributions licensed under CC BY-SA 3.0