Tuesday, October 27, 2020

Turn Off Pooling in ADO.NET

Have you ever wondered how not to use connection pool provided in ADO.NET?

By default, when a connection is first opened using ADO.NET, a connection pool is created based on an exact matching algorithm that associates the pool with the connection string in the connection. Each connection pool is associated with a distinct connection string. 

Thanks EF and ADO.NET for making our lives easier. But sometime we want to take the control.

There are cases that you don't want long running database session (for example, a few hours) to avoid memory leak, database resource constraints, or performance issues in database. Disabling connection pooling can help. If you do want to have a connection closed after connecting to database, you need to set the Pooling flag to false by adding the flag to connection string. 

Just simply append "Pooling=false;" to the connection string. 

That Is Easy.

No comments:

Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...