Walid
Walid

Reputation: 1

Execution timeout expired , in SQL Server, running a stored procedure results in Microsoft.Data.SqlClient.SqlException, backend in ASP.NET Core 6

A stored procedure in SQL Server results in an error

Microsoft.Data.SqlClient.SqlException"

The stored procedure is called from a backed ASP.NET Core 6 Web API.

Details of the exception :

Microsoft.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.
Operation cancelled by user.
The statement has been terminated.
Source=Core Microsoft SqlClient Data Provider
StackTrace:
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.SqlCommand.InternalEndExecuteNonQuery(IAsyncResult asyncResult, Boolean isInternal, String endMethod) at Microsoft.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult) at Microsoft.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task`1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location --- at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.d__15.MoveNext() at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.d__15.MoveNext() at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.d__15.MoveNext() at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.d__13.MoveNext() at Egen.Repository.Repositories.Attendance.AttendanceRepository.d__2.MoveNext() in

Inner Exception 1:
Win32Exception: The wait operation timed out.

What I have done: after changing the timeout the error has not occurred.

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
    this.Database.SetCommandTimeout(TimeSpan.FromSeconds(0));
}

Stored procedure brief: I am providing brief of the stored procedure below.

 WHILE @AttendanceProcessedOn <= @CurrentDateMark
 BEGIN
     -- operations 
   
     SET @AttendanceProcessedOn = DATEADD(DAY, 1 , @AttendanceProcessedOn);
 END

I would like to know if "changing the timeout" is the right approach / best practice to solve this issue? What can be the other options to mitigate this issue?

Upvotes: 0

Views: 579

Answers (0)

Related Questions