Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am calling a stored procedure using entity framework. But I am experiencing below mentioned response from the server.

Here is code

C#
foreach (var item in re.GetProgramScheduleTimeOverlap(StartDate, EndDate, StationId))
                {
                    double dstStartMinutes = (double)item.DstMinutes;
                    double dstEndMinutes = (double)item.DstEndMinutes;
                    tg.Add(new TimeGap { strTime = GetDateWithStartEndTime(item.StartDateTime.AddMinutes(dstStartMinutes), item.EndDateTime.AddMinutes(dstEndMinutes), Convert.ToInt16(timeZoneOffset)), longTime = UTCDateHelper.GetLocalDate(item.EndDateTime.AddMinutes(dstEndMinutes), Convert.ToInt16(timeZoneOffset)).Date.ToString("MM/dd/yyyy"), endDateTime = item.EndDateTime.AddMinutes(dstEndMinutes), startDateTime = item.StartDateTime.AddMinutes(dstStartMinutes) });
                    

                }



C#
Here is Stack Trace:


[Win32Exception (0x80004005): The wait operation timed out]

[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1787962
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341966
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1693
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
   System.Data.SqlClient.SqlDataReader.get_MetaData() +90
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +377
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1421
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +137
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +427

[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
   System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +497
   System.Data.Objects.ObjectContext.CreateFunctionObjectResult(EntityCommand entityCommand, ReadOnlyMetadataCollection`1 entitySets, EdmType[] edmTypes, MergeOption mergeOption) +150
   System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, MergeOption mergeOption, ObjectParameter[] parameters) +315
   System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters) +57
   Radius.Entity.RadiusEntities.GetProgramScheduleList_V2(Nullable`1 startDate, Nullable`1 endDate, Nullable`1 stationId) in d:\Vijay\Clients\David\EPG Interface\Radius.Entity\Radius.Designer.cs:2973
   Radius.Scheduler.SchedulerService.GetProgramSchedule(DateTime StartDate, DateTime EndDate, Int64 StationId, IList`1 tg) in d:\Vijay\Clients\David\EPG Interface\Radius.Scheduler\SchedulerService.cs:807
   Radius.Scheduler.SchedulerService.CheckTimeOverLapWeekday(DateTime startsOn, Nullable`1 endsDate, SchedulerModel sm, Int64 StationId) in d:\Vijay\Clients\David\EPG Interface\Radius.Scheduler\SchedulerService.cs:316
   Radius.Controllers.ProgramScheduleController.CheckTimeOverlap(SchedulerModel sm) in d:\Vijay\Clients\David\EPG Interface\Radius\Controllers\ProgramScheduleController.cs:1471
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +189
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +90
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651516
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


What I have tried:

I tried to check database server logs. I reduced the hits to stored procedure but still issue is not resolving.
Posted
Updated 4-Oct-17 1:28am
Comments
[no name] 21-Nov-16 8:41am    
Increase your command timeout or profile your query and see what is taking so long.

Increase the SqlCommand.Timeout value. I typically just double mine when I run into this issue (however the default value is 30 seconds, and that is typically enough). You could also set it to 0 which indicates no timeout, but that can be dangerous, and lead to an app that hangs.

Secondarily, make sure your stored procedure is working as fast as it can. A poorly implemented stored proc could be your bottleneck.
 
Share this answer
 
v2
Comments
F-ES Sitecore 21-Nov-16 9:02am    
Also make sure it isn't hanging due to a SQL deadlock.
Hi,

Use the SQL server profiler to see why the SP is taking too long to execute.
Remember its always nice to remove the problem than just avoiding it with
CommandTimeout 


Thanks
 
Share this answer
 
Comments
[no name] 14-Feb-17 8:12am    
Really? Your solution is to just repeat the other two solutions from months ago? Those rep points must be really valuable to you.
Philippe Mori 14-Feb-17 20:54pm    
But in my opinion, this is the best answer... If a query take so log that a timeout occurs, then the database should be optimized or the stored procedure should be rewritten in a more efficient way or both or you should consider if you really need that information at once.
[no name] 14-Feb-17 21:00pm    
" this is the best answer", can you explain why this is the "best" answer when it just repeats the other solutions that were posted months ago? It's not the best answer at all. It rep hunting.
Philippe Mori 14-Feb-17 22:37pm    
This one say to fix the slowness. Other answers mainly suggest to increase timeout.
[no name] 16-Feb-17 13:31pm    
No, "make sure your stored procedure is working as fast as it can", posted by John Simmons posted 21-Nov-16 7:43am which was 4 months ago.
And, " profile your query and see what is taking so long" posted by someone named NotPolitcallyCorrect also 4 months ago.
Your query command is taking too long. You need to set the CommandTimeout, so that it is long enough for the command to complete its execution.

Use the following command in your SQL selecting event
SQL
e.Command.CommandTimeout = 100
 
Share this answer
 
Comments
Member 13541763 14-Mar-20 15:32pm    
hi, i am experiencing almost four years after this answer but i don't understand why this query takes too long. i got this from sql profiler and run in mssql while transaction was open in program in debug mode. it took more than 6 minutes with still executing mode.this is just simple select statement. i tried commenting out some columns and ended up successful execution of query with id and productId. any other column inclusion hanged execution. while when transaction was ended in program, this query executed successfully within a second.
note, this is second call my program is making to db after first iteration.
exec sp_executesql N'SELECT
[Extent1].[Id] AS [Id],
[Extent1].[ProductId] AS [ProductId],
[Extent1].[StockId] AS [StockId],
[Extent1].[Quantity] AS [Quantity],
[Extent1].[SalePrice] AS [SalePrice],
[Extent1].[PurchasePrice] AS [PurchasePrice],
[Extent1].[UserLastUpdatedBy] AS [UserLastUpdatedBy],
[Extent1].[DateLastUpdatedOn] AS [DateLastUpdatedOn]
FROM [dbo].[tStockLineItem] AS [Extent1]
WHERE [Extent1].[StockId] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=15

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900