Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
  • ...?
like image 567
Stefan Steinegger Avatar asked Sep 28 '10 06:09

Stefan Steinegger


People also ask

What is the SqlConnection object used for?

A SqlConnection object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used together with SqlDataAdapter and SqlCommand to increase performance when connecting to a Microsoft SQL Server database.

What happens if SqlConnection is not closed?

Not closing connections could cause timeouts as the connection pool may run out of available connections that can be used. A side point to this. If you use the using keyword, that will automatically close the connection for you.

How do you clear a connection pool in SQL Server?

SqlConnection. ClearAllPools() method empties the connection pool. If there are connections in use at the time of the call, they are marked appropriately and will be discarded (instead of being returned to the pool) when Close method is called on them.


1 Answers

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.

like image 111
Darin Dimitrov Avatar answered Sep 17 '22 18:09

Darin Dimitrov