# 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.

- **ID:** `cloud/azure-functions-dynamic-sku-sql-connection-pool-exhausted`
- **Domain:** cloud
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Azure Functions on the Consumption (dynamic) plan scale out rapidly under load, creating many concurrent instances that exhaust the SQL Database connection pool (default max pool size = 100) because each instance opens new connections without reusing them efficiently.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Azure Functions runtime v4 (.NET 8) | active | — | — |
| Azure SQL Database (DTU-based S2 tier) | active | — | — |
| System.Data.SqlClient 4.8.6 | active | — | — |

## Workarounds

1. **Increase the Max Pool Size in the connection string to accommodate more concurrent connections (e.g., add 'Max Pool Size=200'): `Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypwd;Max Pool Size=200;`** (85% success)
   ```
   Increase the Max Pool Size in the connection string to accommodate more concurrent connections (e.g., add 'Max Pool Size=200'): `Server=tcp:myserver.database.windows.net;Database=mydb;User Id=myuser;Password=mypwd;Max Pool Size=200;`
   ```
2. **Implement connection multiplexing by using a singleton HttpClient or Dapper with a shared DbConnection in the Azure Functions startup class to reuse connections across invocations.** (80% success)
   ```
   Implement connection multiplexing by using a singleton HttpClient or Dapper with a shared DbConnection in the Azure Functions startup class to reuse connections across invocations.
   ```

## Dead Ends

- **** — The issue is connection pooling, not the SQL query itself; optimizing a single query won't reduce the number of concurrent connections. (60% fail)
- **** — The function timeout is separate from the SQL connection timeout; increasing it does not affect pool exhaustion. (85% fail)
- **** — Scaling up to a higher SKU may help but is often unnecessary and costly; the root cause is connection management, not database capacity. (40% fail)
