How to handle timeout error on a long running stored proc
Sherpa
306
Reputation points
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;
}
}
Sign in to answer