---
title: "How do I properly configure DbContext pooling to avoid connection-related deadlocks in production?"  
description: "How do I properly configure DbContext pooling to avoid connection-related deadlocks in production?"  
author: "Austin Dcruz"  
published: 2026-09-20  
updated: 2026-09-20  
canonical: https://www.mindstick.com/forum/162188/how-do-i-properly-configure-dbcontext-pooling-to-avoid-connection-related-deadlocks-in-production  
category: "Database Performance"  
tags: ["database", "EntityFramework Core", "infrastructure"]  
reading_time: 1 minute  

---

# How do I properly configure DbContext pooling to avoid connection-related deadlocks in production?

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?


---

Original Source: https://www.mindstick.com/forum/162188/how-do-i-properly-configure-dbcontext-pooling-to-avoid-connection-related-deadlocks-in-production

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
