Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

oracle

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

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.

like image 261
user1012506 Avatar asked Nov 01 '12 14:11

user1012506


2 Answers

You should clear the pool:

 finally
    {
        oraConn.Dispose();
        oraConn.Close();
        OracleConnection.ClearPool(oraConn);
    }
like image 164
Damian21214 Avatar answered Oct 22 '22 07:10

Damian21214


The reason is likely connection pooling. From MSDN:

OracleConnection.Close Method

The Close method rolls back any pending transactions. 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.

like image 35
D'Arcy Rittich Avatar answered Oct 22 '22 06:10

D'Arcy Rittich