Allende
Allende

Reputation: 1482

When should I use ClearALLPools vs ClearPool?

I don't really understand the diff between them, When should I use ClearALLPools instead of ClearPool (or vice verse) ?

Is there any specific scenario to use one or the other ?

Upvotes: 3

Views: 3287

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239636

Connection pooling is massively beneficial, and something you should want to make use of - it separates actual connections to the database from connection objects. You can create as many connection objects as you like, but the number of actual connections used are minimized.

However, there is a cost - if you don't manage your connection objects responsibly, then more actual connections than are (strictly) required will be opened up. At the extreme, this can lead to connections being refused because the pool has hit its limit.

The correct fix is to call neither ClearPool nor ClearAllPools. You should find the location(s) where you're leaking connection objects and fix them. In general, every connection object should either be cleaned up by way of a using statement, or, if it's meant to be kept open, it should be a member of a disposable object that closes the connection as part of its Dispose function.


As to the question, as asked - connection pools are based on the connection strings that are used. If you only use a single connection string for all connections, then the methods are equivalent. If you are using multiple connection strings then the difference becomes apparent, in a hopefully obvious way - that ClearPool only affects connections that are using the same connection string.

Upvotes: 7

Related Questions