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.

Thumbs Up to GitHub Copilot and JetBrains Resharper

Having used AI tool GitHub Copilot since 08/16/2023, I’ve realized that learning GitHub Copilot is like learning a new framework or library ...