OracleConnection.ClearAllPools - 由于对象的当前状态,操作无效

发布于 2024-08-01 14:44:46 字数 1203 浏览 8 评论 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)

关于在尝试清除连接池之前需要处于什么状态,有什么建议吗?

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海里的那抹蓝 2024-08-08 14:44:46

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

所以显然,当没有连接池时,它会抛出此异常,而且我看不出有办法检查它......所以最终唯一的选择是捕获异常

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文