实体框架:ExecuteReader需要一个开放且可用的连接。连接的当前状态为打开

时间:2019-08-17 11:21:21

标签: entity-framework entity-framework-6 entity-framework-4 entity-framework-5

我们正面临来自Entity Framework的以下问题,并且它发生在应用程序的高峰时段,

  • .Net Framework 4.6.1
  • 实体框架6.1.3
  • Web API(Micros服务)
  • SQL Server(Azure)

以下是例外情况详细信息

  

System.InvalidOperationException:ExecuteReader需要打开且可用的Connection。连接的当前状态为打开。

     

在System.Data.SqlClient.SqlConnection.GetOpenConnection(字符串方法)
  在System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String方法,SqlCommand命令)
  在System.Data.SqlClient.SqlCommand.ValidateCommand(String方法,布尔异步)上
  在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
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.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch [TTarget,TInterceptionContext,TResult](TTarget目标,Func 3 operation, TInterceptionContext interceptionContext, Action 3执行,操作3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass65
1.b__64()
  在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction [T](Func 1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass65
1.b__63()
  在System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute [TResult](Func 1 operation)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Internal.LazyEnumerator
1.MoveNext()
  在System.Linq.Enumerable.FirstOrDefault [TSource](IEnumerable`1源)上
  在Telematics.BusinessServices.ErrorService.GetErrorCode(字符串serviceName,字符串operationName,字符串errorType,Int32 errorIndicator)
  在ApiServices.Common.ErrorHandler.ErrorHandlerAttribute.HandleGeneralException(ErrorResponse&errorInfo,IErrorService errorService,字符串serviceName,字符串exceptionMessage,HttpStatusCode&statusCode,字符串operationType)
  在ApiServices.Common.ErrorHandler.ErrorHandlerAttribute.OnException(HttpActionExecutedContext actionExecutedContext)

0 个答案:

没有答案