Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › ASP.NET Core

How to Diagnose and Fix Connection Pool Exhaustion in ASP.NET Core APIs

By Freedom251 Team · · 7 min read

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When an ASP.NET Core API times out while obtaining a database connection, the immediate problem is that a connection was not available from the relevant driver pool before the connection timeout. That does not, by itself, prove there is a connection leak: slow or blocked operations, long transactions, too much concurrent demand, fragmented pools, or a database connection limit can produce the same symptom.

Start by confirming the failing stage, then measure connection hold times and pool behavior alongside database activity. Increase pool limits only after you have calculated the total demand across pools, processes, and API instances and verified that the database can support it.

As an Amazon Associate I earn from qualifying purchases.

What the connection-pool timeout means

Microsoft documents the SqlClient exception as:

System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The failure occurs while the client is trying to acquire a connection, before the database command can run on that connection. It means no connection became available to that open attempt before the connection timeout expired. It does not identify why the pool was unavailable. Microsoft’s SqlClient troubleshooting guide, updated May 27, 2026, lists causes that include connections not being closed, long-running work, blocking, and pool pressure.

Connection pooling belongs to the database provider’s driver, not to ASP.NET Core or EF Core. EF Core generally opens a connection shortly before a database operation and closes it afterward, returning it to the underlying driver pool. DbContext pooling is a separate optimization: it reuses DbContext instances and does not increase the number of database connections available.

The settings and diagnostics below are specifically for Microsoft.Data.SqlClient. Other providers can have different defaults, pool keys, and telemetry; check the documentation for the actual driver and version used by the API.

Confirm the failure stage and capture the setup

First, distinguish an open-timeout from a command timeout. Use the exception and stack trace to establish whether the error occurs while opening or acquiring a connection, rather than after a command has started. Then record the following for the affected service and time window:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • The database provider and driver version.
  • The effective connection-string options, with passwords, tokens, and other secrets removed.
  • The database endpoint and deployment topology, including process and API-instance counts.
  • Request concurrency and the timing of the errors, latency increase, and any deployments or failovers.
  • Whether the affected path uses EF Core, manually opened connections, explicit transactions, or ambient transactions.

For SqlClient, “Connect Timeout” is the time an open attempt can wait for a connection; it is distinct from a database command’s execution timeout. A longer connection timeout may delay the error, but it does not make another connection available.

Check whether connections are held too long

Inspect every path that opens or uses a connection, including cancellation and exception paths. A connection can remain unavailable while a reader is still being consumed, a command is still running, or a transaction has not completed. Check deterministic disposal of connections, readers, commands, and transactions; also look for code that catches an exception but skips cleanup.

EF Core normally manages open and close around an operation. If application code manually opens a DbConnection, ensure it is closed or restored to the expected state before a pooled DbContext is reused. Context pooling does not clean up arbitrary connection state left behind by application code.

Look for long or abandoned transactions

Keep transactions limited to the work that must be atomic, and make sure every transaction completes or rolls back. Microsoft’s SqlClient pooling guidance notes that a connection logically closed while enlisted in an ambient transaction can remain in a transaction-specific pool subdivision until that transaction completes. Meanwhile, the transaction may continue to hold server-side locks or other state. Investigate transaction age and database blocking together rather than treating a high connection count as a client-only issue.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Measure the client pool and the database together

For Microsoft.Data.SqlClient on .NET Core or .NET Standard, use the driver’s event counters to observe pool behavior. Microsoft’s diagnostic-counters documentation was updated August 24, 2026. Track active pool groups and pools, and available and active resources where the driver exposes them. Review hard connects (physical opens), soft connects (pool checkouts and returns), stasis, and reclaimed connections.

A reclaimed connection is a reason to inspect code paths that did not call Close or Dispose; it is a clue to investigate, not proof that every timeout is a leak. Use targeted event-source tracing only for a bounded diagnostic window: it is verbose and can include connection metadata.

At the same time, inspect database sessions, waits, blocking, and resource limits. If the client shows connections in use while the server shows long-running or blocked sessions, address query, transaction, or database capacity problems. If client-side pool counts multiply unexpectedly without a matching rise in intended workload, inspect connection-string variation and identity-dependent pools.

Separate database pool pressure from ThreadPool starvation

ThreadPool starvation can also cause slow requests, but it concerns worker threads, not database connections. For .NET 9 and later, Microsoft’s ThreadPool starvation tutorial describes using dotnet-counters to identify likely starvation, then dotnet-stack or dotnet-trace to investigate work holding threads. Treat that as a separate hypothesis and correlate its evidence with database-pool and server telemetry.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check for fragmented SqlClient pools

SqlClient pools are keyed by connection configuration and identity details. An application can therefore have several smaller pools instead of one shared pool, leaving capacity stranded in pools that other requests cannot use. Microsoft’s SqlClient troubleshooting guidance identifies patterns to review:

  • Connection strings that differ in keyword order or use different aliases for equivalent settings.
  • Per-user, per-customer, per-request, or per-database connection strings.
  • Different integrated Windows identities.
  • New credential or callback objects created for each request, or changing direct access-token strings.
  • High-cardinality application or workstation names in connection configuration.

Normalize connection-string construction and reuse stable credential or callback objects where appropriate. If the service intentionally connects to many databases or identities, count those pool subdivisions in the capacity plan instead of assuming a single pool serves the whole API.

Understand SqlClient’s default limits before changing them

Microsoft’s current Microsoft.Data.SqlClient pooling documentation, accessed in 2026, gives the following defaults for an individual pool. These are driver defaults, not universal ASP.NET Core or EF Core settings; connection-string configuration can override them.

SqlClient setting Documented default What it controls
Pooling true Whether the connection pool is enabled.
Min Pool Size 0 The minimum number of connections retained in a pool.
Max Pool Size 100 connections per pool The maximum number of connections in that pool.
Connect Timeout 15 seconds How long an open attempt waits before timing out.

Those figures describe a single SqlClient pool. Pools are process-local, and distinct pool keys, worker processes, containers, hosts, and API replicas can multiply aggregate demand. A setting of 100 is not a 100-connection budget for the entire service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a fix from the evidence

Fix lifecycle problems before raising limits

If connections are not being returned promptly, correct disposal and transaction completion first. A larger pool can postpone the next timeout while allowing more concurrent work to reach the database; it can hide the underlying defect and increase server load.

Reduce connection hold time when work is slow or blocked

Use session, wait, and blocking evidence to find commands or transactions that occupy connections for too long. Address the query or blocking cause, and avoid holding a connection across unrelated application work. Reducing hold time can improve throughput without increasing the number of database sessions.

Normalize pool keys when demand is split across pools

If telemetry indicates many pools caused by inconsistent configuration or per-request identity variation, make equivalent connection configurations stable. For intentional multi-database or multi-identity workloads, include the resulting pool count in concurrency and server-capacity estimates.

Raise Max Pool Size only with a fleet-wide capacity calculation

Before increasing SqlClient’s maximum, establish that connections are disposed, operations and transactions finish promptly, and the database is not already constrained by query load, blocking, or connection limits. Estimate the potential aggregate as the configured maximum multiplied by the number of relevant pools in each process and by the number of processes or replicas. Verify that the database can sustain that demand, including other applications that share it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A positive Min Pool Size retains idle connections and should have a measurement-based reason. Raising minimums across many pools or replicas can create a substantial idle connection footprint even when request traffic is low.

Limit concurrency or add database capacity when demand is genuinely too high

If properly short-lived operations still create peaks above the database’s sustainable connection or workload budget, bound application concurrency or provide capacity the database can support. Increasing the client pool alone is not a database-capacity fix. A database service change is relevant only when server-side capacity is the demonstrated constraint, not when the API is leaking connections or fragmenting pools.

Avoid fixes that create a second incident

Do not clear pools as routine maintenance

ClearPool and ClearAllPools reset or empty pools. Connections currently in use are discarded when returned, and subsequent opens need physical logins. Current SqlClient guidance reserves clearing for a real credential, token, or configuration boundary, or diagnosed stale connections. It is not a substitute for disposal and can trigger a burst of physical logins.

Do not treat retries or longer timeouts as capacity

Retries can increase pressure during an outage, failover, or scale-out event if many requests repeatedly attempt to connect. Bound connection attempts and retries, and verify that the database and query behavior support the target concurrency. SqlClient’s authentication blocking period is a separate behavior from pool-checkout timeout: after an authentication failure, the documented first blocking period is five seconds and repeated failures can double it up to one minute. Disabling that behavior can turn credential or network outages into repeated authentication attempts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

ASP.NET CoreDatabase connectionsEntity Framework CoreMicrosoft.Data.SqlClientSQL ServerTroubleshooting

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.