Reputation: 65
In my ASP.NET MVC (C#) application, i am using Entity Framework and calling Stored Procudures like this :
public virtual ObjectResult<ART_USP_GetAssetReportGridList_Result> ART_USP_GetAssetReportGridList(string searchExpression, string sortExpression, string sortDirection, Nullable<int> startIndex, Nullable<int> pageSize, ObjectParameter count)
{
var searchExpressionParameter = searchExpression != null ?
new ObjectParameter("SearchExpression", searchExpression) :
new ObjectParameter("SearchExpression", typeof(string));
var sortExpressionParameter = sortExpression != null ?
new ObjectParameter("SortExpression", sortExpression) :
new ObjectParameter("SortExpression", typeof(string));
var sortDirectionParameter = sortDirection != null ?
new ObjectParameter("SortDirection", sortDirection) :
new ObjectParameter("SortDirection", typeof(string));
var startIndexParameter = startIndex.HasValue ?
new ObjectParameter("StartIndex", startIndex) :
new ObjectParameter("StartIndex", typeof(int));
var pageSizeParameter = pageSize.HasValue ?
new ObjectParameter("PageSize", pageSize) :
new ObjectParameter("PageSize", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ART_USP_GetAssetReportGridList_Result>("ART_USP_GetAssetReportGridList", searchExpressionParameter, sortExpressionParameter, sortDirectionParameter, startIndexParameter, pageSizeParameter, count);
}
Here ART_USP_GetAssetReportGridList is the stored procedure name. This is a synchronous call. If the number of records are more than 3000 this call is giving me Time-out error.
How can i make this call asynchronously without getting the Time-out error?
Upvotes: 1
Views: 1416
Reputation: 56
Please try this
var data = ObjectContext.Database.SqlQuery<ART_USP_GetAssetReportGridList_Result>("ART_USP_GetAssetReportGridList", searchExpressionParameter, sortExpressionParameter, sortDirectionParameter, startIndexParameter, pageSizeParameter, count).FirstOrDefaultAsync();
Upvotes: 0
Reputation: 908
You may increase the timeout on specific operations as follows.
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180; // in sec
Or set this code on your DbContext constructor.
Upvotes: 1
Reputation: 6222
Calling this asyncronously wont make any difference. You are getting a command timeout error. I order to avoid this you should increase the CommandTimeout setting of the SQL connection. But I would very much recommend not doing this, and looking at your stored procedure efficiency - the 30 second default timeout should be way, way more than you need.
Upvotes: 0