Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Entity Framework use database connection pooling? and is it by default?

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.

like image 693
bashmohandes Avatar asked May 17 '10 07:05

bashmohandes


People also ask

Is connection pooling enabled by default?

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.

Does EF core use connection pooling?

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).

How does Entity Framework manage connections?

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.


1 Answers

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.

like image 76
James H Avatar answered Oct 06 '22 20:10

James H