简体   繁体   English

oracleConnection.close() 不要在我的会话浏览器中关闭连接

[英]oracleConnection.close() dont close the connection in my session browser

I make run of test connection, I expect to see clear session browser, but at the end of the program, I see more then 6 sessions in my session browser我进行了测试连接,我希望看到清晰的会话浏览器,但是在程序结束时,我在会话浏览器中看到了超过 6 个会话

This is the code:这是代码:

private void testConnection()        
{   
        string connectionString = "data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=1111)(PORT=1699))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = abcd)));Min Pool Size=10; Connection Lifetime=120;";

        OracleConnection oraConn = new OracleConnection(connectionString);

        try
        {
            oraConn.Open();
        }

        catch (Exception e)
        {
        }

        finally
        {
            oraConn.Dispose();
            oraConn.Close();
        }

    }

I need a solution to close session totaly.我需要一个解决方案来完全关闭会话。

You should clear the pool:您应该清除池:

 finally
    {
        oraConn.Dispose();
        oraConn.Close();
        OracleConnection.ClearPool(oraConn);
    }

The reason is likely connection pooling.原因可能是连接池。 From MSDN:来自 MSDN:

OracleConnection.Close Method OracleConnection.Close 方法

The Close method rolls back any pending transactions. Close 方法回滚任何挂起的事务。 It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.然后它释放与连接池的连接,或者如果连接池被禁用则关闭连接。

So, your connection instance will get disposed of within C# but the connection may stay open in the pool, so that a new open connection instance may be quickly provided the next time you request one.因此,您的连接实例将在 C# 中被处理,但连接可能在池中保持打开状态,以便您下次请求时可以快速提供一个新的打开连接实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM