Connection Pooling

  • I've been looking at connection pooling (because I had a connection leak) and largely understand the principal.

    However, I've come across this (below) in some code...

    ConnectionState originalConnSt = dbConnection.State;

    try

    {

    do stuff, including opening the connection if it's not open

    }

    finally

    {

    if(originalConnSt == ConnectionState.Closed)

    { dbConnection.Close() }

    }

    Everything I read says ALWAYS close the connection when you've finished using it. This returns it to the pool.

    I guess what was trying to be achieved here was leaving the connection open between calls.

    Is this actually any more efficient than opening and closing the connection each time, given that it would be taken from the pool anyway?

    Thanks for any advice.

  • use using(...) {....}, for more information see MSDN.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply