Click here to Skip to main content
13,634,016 members
Rate this:
Please Sign up or sign in to vote.
I am calling a stored procedure using entity framework. But I am experiencing below mentioned response from the server.

Here is code

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) });


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 21-Nov-16 2:37am
Updated 4-Oct-17 1:28am
NotPolitcallyCorrect 21-Nov-16 8:41am
Increase your command timeout or profile your query and see what is taking so long.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
F-ES Sitecore 21-Nov-16 9:02am
Also make sure it isn't hanging due to a SQL deadlock.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


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

NotPolitcallyCorrect 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.
NotPolitcallyCorrect 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.
NotPolitcallyCorrect 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
e.Command.CommandTimeout = 100

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180712.1 | Last Updated 4 Oct 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100