I have been searching for a while about how EF utilizes connections to SQL Server DB, and whether it is using Connection pools under the hood, but I couldn't find any details about that.
By default, connection pooling is enabled in ADO.NET. Unless you explicitly disable it, the pooler optimizes the connections as they are opened and closed in your application. You can also supply several connection string modifiers to control connection pooling behavior.
Pooling without dependency injection was introduced in EF Core 6.0. The poolSize parameter of the PooledDbContextFactory constructor sets the maximum number of instances retained by the pool (defaults to 1024 in EF Core 6.0, and to 128 in previous versions).
Entity Framework manages a connection pool, which means that EF will reuse connections when possible and only create new ones when it needs to. Whether or not each call creates a new connection depends on many factors. So it's hard to say whether any given set of calls will or will not create new connections.
Connection pooling is handled by the underlying datasource provider, and not by the Entity Framework. The MS SQL provider, for example, supports and uses connection pooling by default.
Using Connection Pooling with SQL Server
is a good reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With