Home > database >  System.Data.SqlClient.SqlException (The wait operation timed out) when debugging only
System.Data.SqlClient.SqlException (The wait operation timed out) when debugging only

Time:12-10

The code code works with smaller queries even on debug. I tried some larger queries, and it works with the server/live version but not when debugging with visual studio. I tried the same query with SSMS and it worked fine, pretty quick too.

The query is via a stored procedure:

using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
{
   partialReport = conn.Query<MonthlyReporting>("PartialReport", new { ClassLevel = (int)instruct, StartDate = startDate, EndDate = endDate, IncludeMarried = includeMarried }, commandType: CommandType.StoredProcedure).ToList();

   // program does stuff here
}

The full exception details is:

System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Source=.Net SqlClient Data Provider

StackTrace:
Cannot evaluate the exception stack trace

Inner Exception 1:
Win32Exception: The wait operation timed out

The code is identical between the Server and Debug versions of the code, and the debug database is the same as the server/live database (although a few days older). Likewise, the CONNECTION_STRING is different, pointing to the debug/live database respectively.

Once again, this DOES work even when debugging with smaller queries.

CodePudding user response:

I got it to work by doing essentially nothing. I encountered the same problem at a different part of the code, but I pressed continue after the error. I refreshed the page a few times to see if there was any consistency with the time it took for the error to appear. I was doing this because I tried changing the connection timeout with no success, (the refreshing was done with my original connection timeout settings). after refreshing a few times, the problem just went away (at both locations in the code). I think the problem is caused when I copy the database from the live version/server to the local debug version.

  • Related