OracleConnection.ClearAllPools - Operation is not valid due to the current state of the object

断了今生、忘了曾经 提交于 2020-01-14 05:33:10

问题


I have the following code in an ashx file - don't ask why ;-)

<%@ WebHandler Language="C#" Class="Site.Pool" %>

using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.SessionState;

using Core.Database;
using Core.ITables;
using Online.Server.Busi;
using Online.Server.ITables;
using XactNet.Busi;

namespace Site
{
    public class Pool : IHttpHandler, IRequiresSessionState
    {
            public void ProcessRequest(HttpContext context)
            {
            try
            {
                Oracle.DataAccess.Client.OracleConnection.ClearAllPools();
                context.Response.Write("SUCCESS");
            }
            catch (Exception e)
            {
                context.Response.Write(e.ToString());
            }

        }

            public bool IsReusable
            {
                get { return false; }
        }
        }
}

When called, the exception gets written out:

System.InvalidOperationException: Operation is not valid due to the current state of the object. 
at Oracle.DataAccess.Client.OracleConnection.ClearAllPools() 
at Site.Pool.ProcessRequest(HttpContext context)

Any suggestions as to what state the connection pools need to be in before trying to clear them?

Thanks,


回答1:


This is the default error message for InvalidOperationException, so don't assume it has any significant meaning in this case... apparently Oracle didn't bother to write an explicit error message.

Here's the code of the ClearAllPools method, according to Reflector :

public static void ClearAllPools()
{
    if (!OracleInit.bSetDllDirectoryInvoked)
    {
        OracleInit.Initialize();
    }
    if (((ConnectionDispenser.m_ConnectionPools == null) || (ConnectionDispenser.m_ConnectionPools.Count == 0)) && ((ConnectionDispenser.m_htSvcToRLB == null) || (ConnectionDispenser.m_htSvcToRLB.Count == 0)))
    {
        throw new InvalidOperationException();
    }
    ConnectionDispenser.ClearAllPools();
}

So apparently it throws this exception when there is no connection pool, and I see no way of checking that... so eventually the only option is to catch the exception



来源:https://stackoverflow.com/questions/1289057/oracleconnection-clearallpools-operation-is-not-valid-due-to-the-current-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!