We're running a busy ASP.NET Core Web API backed by SQL Server, and lately the logs show intermittent deadlocks tied to database connections. I suspect it's related to how we're managing DbContext instances, especially since we enabled connection pooling at the server level.
Our current setup registers AddDbContext with a scoped lifetime in Program.cs. Under load, connections seem to be held longer than expected, and I've noticed some requests timing out while waiting for a free connection from the pool.
Is there a recommended way to tune the pool size or configure DbContext options to reduce contention? Should we be looking at EnableRetryOnFailure, or is this more about ensuring we're not accidentally keeping connections open across await boundaries?
Can you answer this question?
Write Answer0 Answers