Clearing SQL-Server connection pool

  • Thread starter Thread starter Ramon de Klein
  • Start date Start date
R

Ramon de Klein

We use an automated testing tool and I restore the
database before each testcase that modifies the database.
Therefore I need to kill all open connections to the SQL-
Server database (using the T-SQL KILL statement).
Unfortunately, the SQL connection pool isn't notified that
the connection is cancelled. So when a new connection is
opened (that is retrieved from the pool) a 'General
Network Error' occurs.

I have solved this to disable connection pooling while
testing (setting "pooling='false'" in the connection
string). I would rather flush the connection pool, but I
cannot find a way to do this from a .NET environment.

Does anyone know how to manage the connection pool from
within a .NET application?
 
Hi Ramon,

You are correct that pool isn't notified.
The way the ado.net works is that: when it tries to open a (faulty or
broken) connection it will remove it from the pool.
So, you should catch that kind of exception and retry the connection.Open.
 
Back
Top