0

我在 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)

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

谢谢,

4

1 回答 1

4

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

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

于 2009-08-17T17:02:07.013 回答