Clearing SQL-Server connection pool

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?
 
M

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top