簡體   English   中英

ASP.NET MVC4 和實體框架上的超時問題

[英]Timeout issue on ASP.NET MVC4 and Entity Framework

我在我們的 ASP.NET MVC 應用程序之一中收到以下超時錯誤。 下面是堆棧跟蹤。

奇怪的是,用戶在單擊調用 LINQ 查詢的按鈕后僅約 5 秒就會收到錯誤消息。 但是,如果她再次嘗試單擊該按鈕,大約一分鍾后,就會出現報告並且一切正常。

她在第一次嘗試僅 5 秒后收到錯誤這一事實告訴我,這不是超時問題……或者是嗎? LINQ 查詢有點復雜,但是當她第二次單擊該按鈕時它可以正常工作。 任何建議這可能是什么?

這是導致超時的代碼(LINQ 查詢):

    private List<ProductionReportExcelWriter.ProductLine> GetProductList(ProductionReporViewInput input)
    {
        return _context.Set<Product>()
            .Include(p => p.Dough)
            .Include(oi => oi.OrderItems)
            .Include(oi => oi.OrderItems.Select(o => o.Order))
            .Include(oi => oi.OrderItems.Select(o => o.Order.Client))
            .AsQueryable()
            .ForNextOrderDate(input.ReportDate)
            .WithActiveClients()
            .ForOrdersItemsWithQuantities()
            .WithoutHiddenProducts().ToList()
            .Select(p => new ProductionReportExcelWriter.ProductLine
            {
                ProductId = p.Id,
                Dough = p.Dough.Name,
                ProductCode = p.ProductCode,
                DoughPosition = p.Dough.Position,
                Description = p.Description,
                Weight = p.Weight,
                Account = p.Account,
            }).ToList();
    }

錯誤信息:

System.Data.Entity.Core.EntityCommandExecutionException:執行命令定義時出錯。 有關詳細信息,請參閱內部異常。

System.Data.SqlClient.SqlException:超時已過期。 操作完成前超時時間已過或服務器未響應。

System.ComponentModel.Win32Exception:等待操作超時

完整的堆棧跟蹤:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. 
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
System.ComponentModel.Win32Exception: The wait operation timed out
--- End of inner exception stack trace ---  
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)  
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)  
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)  
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)  
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()  
at System.Data.SqlClient.SqlDataReader.get_MetaData()  
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)  
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)  
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)  
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)  
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)  
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)  
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)  
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)  
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)  
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)  
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)  
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)  
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)  
--- End of inner exception stack trace ---  
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)  
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)  
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__2()  
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)  
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()  
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)  
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)  
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()  
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()  
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)  
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)  
at Arhoma.Core.Views.ProductionReportViewFactory.GetProductList(ProductionReporViewInput input) in C:\Projects\webapp-commande\core-commande\Views\ProductionReportViewFactory.cs:line 66
at Arhoma.Core.Views.ProductionReportViewFactory.CreateProductionReportExcelWriterModel(ProductionReporViewInput input) in C:\Projects\webapp-commande\core-commande\Views\ProductionReportViewFactory.cs:line 37
at Arhoma.Core.Views.ProductionReportViewFactory.Load(ProductionReporViewInput input) in C:\Projects\webapp-commande\core-commande\Views\ProductionReportViewFactory.cs:line 26
at Arhoma.Core.ViewRepositoryOutputBuilder`1.Using[TInput](TInput input) in C:\Projects\webapp-commande\core-commande\ViewRepository.cs:line 42
at Arhoma.WebApp.Controllers.ClosingController.ProductionReport(Nullable`1 date) in C:\Projects\webapp-commande\webapp-commande\Controllers\ClosingController.cs:line 47
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

在寫入連接字符串標記的 web.config 文件中,像這樣增加超時時間 Timeout=200 或 Timeout=500。 例如——

<add name="ConnectionString" connectionString="Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;Password=sa@123;Connect Timeout=200" providerName="System.Data.SqlClient"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM