Search code examples
.netsql-serverado.netconnection-pooling

SqlConnection.ClearAllPools, what is cleared?


I have an application which uses SqlConnection.ClearAllPools to close all connections before dropping a database.

There is a case where a connection is still there. This connection had been created in another application domain.

So I wonder which connections are closed by SqlConnection.ClearAllPools?

  • Only the connections opened by the calling process (or AppDomain)?
  • All the connections opened by this machine?
  • ...?

Solution

  • It closes all the connections opened by the calling process only. It empties all the connection pools which are bound to the process. Quote:

    Connection pool and connection string go hand in hand. Every connection pool is associated with a distinct connection string and that too, it is specific to the application. In turn, what it means is – a separate connection pool is maintained for every distinct process, app domain and connection string.