【问题标题】:OracleConnection.ClearAllPools - Operation is not valid due to the current state of the objectOracleConnection.ClearAllPools - 由于对象的当前状态,操作无效
【发布时间】:2009-08-17 16:38:19
【问题描述】:

我在 ashx 文件中有以下代码 - 不要问为什么 ;-)

<%@ 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; }
        }
        }
}

调用时,异常被写出:

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)

关于在尝试清除连接池之前需要处于什么状态的任何建议?

谢谢,

【问题讨论】:

    标签: c# asp.net oracleclient


    【解决方案1】:

    这是 InvalidOperationException 的默认错误消息,所以不要假设它在这种情况下有任何重要意义......显然 Oracle 并没有费心写明确的错误消息。

    根据 Reflector,这是 ClearAllPools 方法的代码:

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

    显然,当没有连接池时它会抛出这个异常,我看不出有什么方法可以检查......所以最终唯一的选择是捕获这个异常

    【讨论】:

    • 是的,我也在反射器中打开它,看到了同样的结果。不知道为什么我当时没有连接池(也许当我把 ashx 文件放在那里时应用程序重新启动了......)
    猜你喜欢
    • 2010-10-18
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多