{
  "id": "dotnet/ef-core-connection-timeout",
  "signature": "Microsoft.Data.SqlClient.SqlException (0x80131904): Connection 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.",
  "signature_zh": "Microsoft.Data.SqlClient.SqlException (0x80131904): 连接超时已过期。在从池中获取连接之前超时时间已过。这可能是因为所有池化连接都在使用中且达到了最大池大小。",
  "regex": "Connection Timeout Expired.*max pool size was reached",
  "domain": "dotnet",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "The connection pool is exhausted because connections are not being closed/disposed properly, or the pool size is too small for the concurrent load.",
  "root_cause_type": "generic",
  "root_cause_zh": "连接池耗尽，因为连接未正确关闭/释放，或者池大小对于并发负载来说太小。",
  "versions": [
    {
      "version": "net6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "net9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing Max Pool Size in connection string to a very high value (e.g., 1000)",
      "why_fails": "This only masks the underlying issue of connection leaks; the pool will eventually exhaust again under higher load.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Restarting the application or IIS pool to clear connections",
      "why_fails": "Temporary fix; connections will leak again once the app runs, as the root cause (missing Dispose) persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disabling connection pooling entirely (Pooling=false)",
      "why_fails": "Severely impacts performance by creating a new connection for every request, leading to slower response times and potential socket exhaustion.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure all DbContext instances are properly disposed by using 'using' blocks or dependency injection with AddDbContext and scoped lifetime. Example: 'using (var context = new MyDbContext()) { ... }' or services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Scoped)",
      "success_rate": 0.9,
      "how": "Ensure all DbContext instances are properly disposed by using 'using' blocks or dependency injection with AddDbContext and scoped lifetime. Example: 'using (var context = new MyDbContext()) { ... }' or services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Scoped)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase connection pool size and add connection leak detection. Set 'Max Pool Size=200; Connection Lifetime=300' in the connection string, and enable 'Pooling=True' with 'Load Balance Timeout=30'. Also monitor with 'SELECT * FROM sys.dm_exec_sessions' to identify orphaned connections.",
      "success_rate": 0.8,
      "how": "Increase connection pool size and add connection leak detection. Set 'Max Pool Size=200; Connection Lifetime=300' in the connection string, and enable 'Pooling=True' with 'Load Balance Timeout=30'. Also monitor with 'SELECT * FROM sys.dm_exec_sessions' to identify orphaned connections.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use 'using var connection = new SqlConnection(connectionString);' and wrap in try-finally or use 'await using' for async operations. For EF Core, ensure 'context.Database.CloseConnection()' is called in long-running operations.",
      "success_rate": 0.85,
      "how": "Use 'using var connection = new SqlConnection(connectionString);' and wrap in try-finally or use 'await using' for async operations. For EF Core, ensure 'context.Database.CloseConnection()' is called in long-running operations.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure all DbContext instances are properly disposed by using 'using' blocks or dependency injection with AddDbContext and scoped lifetime. Example: 'using (var context = new MyDbContext()) { ... }' or services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Scoped)",
    "Increase connection pool size and add connection leak detection. Set 'Max Pool Size=200; Connection Lifetime=300' in the connection string, and enable 'Pooling=True' with 'Load Balance Timeout=30'. Also monitor with 'SELECT * FROM sys.dm_exec_sessions' to identify orphaned connections.",
    "Use 'using var connection = new SqlConnection(connectionString);' and wrap in try-finally or use 'await using' for async operations. For EF Core, ensure 'context.Database.CloseConnection()' is called in long-running operations."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-connection-pooling",
  "official_doc_section": null,
  "error_code": "0x80131904",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}