How to handle timeout error on a long running stored proc

Sherpa 306 Reputation points
2024-08-30T17:45:18.0533333+00:00

I am working on an Asp.Net Core 6 project. I am using Dapper for my data access. When I used the data access on a long-running stored proc I got a timeout error. This stored proc usually took 11 mins to complete when run on SSMS. When I tried commandTimeout:900, the query was completed right away but returned no result set. I also tried the QueryAsync( ) method with the same timeout issue.

public IEnumerable<ProjectDetailsByYear> GetRiskByYearAsync(ReportsConfigurationVM reportsConfigurationVM)
{
    var parameters = new DynamicParameters();
    parameters.Add("@ProjectDetailsID", reportsConfigurationVM.ProjectDetailsID,DbType.String);
    parameters.Add("@ProjectNumber", reportsConfigurationVM.ProjectNumber, DbType.String);
    parameters.Add("@ProjectName", reportsConfigurationVM.ProjectName, DbType.String);  


    using (var connection = new SqlConnection(_connectionString))
    {
        
	    var projectDetails = connection.Query<ProjectDetailsByYear>("proc_GetProjectDetailsByYear", 	    	    parameters, commandType: CommandType.StoredProcedure, commandTimeout:null);
            return (IEnumerable<ProjectDetailsByYear>)projectDetails;
    }
}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,515 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.