一段时间不活动后,Oracle数据库中的EntityCommandExecutionException

时间:2015-08-06 20:55:52

标签: .net asp.net-mvc oracle entity-framework dbcontext

我在MVC应用程序中尝试访问数据库(通过实体框架/ DbContext)一段时间不活动(约2小时?)后,我收到了Oracle数据库生成的异常。作为一种解决方法,我“捕获”此异常,然后重复查询操作,然后始终成功。以下是例外情况:

ORA-12570: Network Session: Unexpected packet read error

Stack trace:
   at Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel level, OracleTraceTag tag, Exception ex)
   at OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int64 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Int64[]& rowsAffectedByArrayBind, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause, List`1& implicitRSList, Boolean bLOBArrayFetchRequired)
   at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, Boolean isDescribeOnly, Boolean isFromEF)
   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   at Oracle.ManagedDataAccess.Client.OracleCommand.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)

Inner:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

以下是代码:

public IEnumerable<string> GetSimpleItems()
{
    List<string> values;

    using (var db = new LLL_SST())
    {
        try
        {
            values = db.VW_SST_PLAN_RCPT_UNITS.Select(c => c.BUY_MODE).Distinct().ToList();

        }
        catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
        {
            //try again after db wakes up
            values = db.VW_SST_PLAN_RCPT_UNITS.Select(c => c.BUY_MODE).Distinct().ToList();
        }
    }

    return values;

}

Oracle中必须有一个配置设置才能使侦听进程进入休眠状态。有谁知道这究竟是什么?有关解决这个问题的正确解决方案的任何想法吗?

先谢谢大家!

0 个答案:

没有答案