Connection Pool Control in .NET 2.0

As known, connection pooling is an inbuilt feature of ADO.NET that internally caches open database connections to serve for later requests. While the need to manually clear the connections in the pool may not really arise, .NET 2.0 gives you a knob to do so. Meet these two methods:

System.Data.SqlClient.SqlConnection.ClearPool();

System.Data.SqlClient.SqlConnection.ClearAllPools();

However, these methods do not clear/close the connections in the pool immediately. Rather, the methods “mark” any existing connections in the pool for close so that they are not used to fulfill database connection requests – this forces to create a new connection and return it to the caller. The actual closing of connections will happen at a later point of time.