ASP.NET Core Web API Interview Question #123
What is connection pooling and how does it affect Web APIs?
Dependency Injection, Services, EF Core, Async & Data Access Mid-Level Intermediate
Quick Interview Answer
ADO.NET database providers normally pool physical database connections. Opening a connection typically obtains one from the pool and closing or disposing it returns it for reuse, reducing connection-establishment cost.
Detailed Explanation
ADO.NET database providers normally pool physical database connections. Opening a connection typically obtains one from the pool and closing or disposing it returns it for reuse, reducing connection-establishment cost.
Applications should open connections only as needed and dispose them promptly. Increasing pool sizes is not a substitute for fixing slow queries, long transactions, or excessive database concurrency.
Code Example
// EF Core manages connection use for normal queries.
var product = await _db.Products
.AsNoTracking()
.SingleOrDefaultAsync(x => x.Id == id, token);