Users Pricing

forum

Home Forums How do I properly configure DbContext pooling to avoid connection-related deadlocks in production? – MindStick

How do I properly configure DbContext pooling to avoid connection-related deadlocks in production?

Austin Dcruz 10 20 Sep 2026

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?


0 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md