我在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)
在尝试清除连接池之前,有关连接池需要处于什么状态的任何建议?
谢谢,
答案 0 :(得分: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();
}
所以显然当没有连接池时它抛出了这个异常,我看不到检查那个...所以最终唯一的选择是捕获异常