{
  "id": "dotnet/ef-core-sql-timeout",
  "signature": "Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.",
  "signature_zh": "Microsoft.Data.SqlClient.SqlException (0x80131904): 执行超时已过期。操作完成之前超时时间已到或服务器未响应。",
  "regex": "Execution Timeout Expired\\. The timeout period elapsed prior to completion of the operation",
  "domain": "dotnet",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Entity Framework Core query or command exceeds the default 30-second command timeout due to complex joins, unindexed queries, or large result sets in SQL Server.",
  "root_cause_type": "generic",
  "root_cause_zh": "Entity Framework Core 查询或命令因复杂联接、未索引查询或结果集过大而超过默认的 30 秒命令超时。",
  "versions": [
    {
      "version": ".NET 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "EF Core 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "EF Core 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "EF Core 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Set CommandTimeout to 0 (infinite) in DbContext options",
      "why_fails": "Infinite timeout can cause indefinite hangs and resource exhaustion; it masks the underlying query performance issue.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Add .AsNoTracking() to all queries",
      "why_fails": "AsNoTracking reduces overhead but does not fix slow queries; timeout still occurs if the query is slow due to missing indexes.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase SqlCommand timeout in appsettings",
      "why_fails": "Increasing timeout without optimizing the query or adding indexes only delays the failure; the query may still fail under load.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add database indexes on columns used in WHERE and JOIN clauses. Example: CREATE INDEX IX_Orders_CustomerId ON Orders (CustomerId);",
      "success_rate": 0.9,
      "how": "Add database indexes on columns used in WHERE and JOIN clauses. Example: CREATE INDEX IX_Orders_CustomerId ON Orders (CustomerId);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set CommandTimeout to a higher value (e.g., 120 seconds) in OnConfiguring: optionsBuilder.UseSqlServer(connectionString, opts => opts.CommandTimeout(120));",
      "success_rate": 0.75,
      "how": "Set CommandTimeout to a higher value (e.g., 120 seconds) in OnConfiguring: optionsBuilder.UseSqlServer(connectionString, opts => opts.CommandTimeout(120));",
      "condition": "",
      "sources": []
    },
    {
      "action": "Optimize LINQ query by using .AsSplitQuery() to avoid Cartesian explosion: context.Orders.Include(o => o.Details).AsSplitQuery().ToList();",
      "success_rate": 0.85,
      "how": "Optimize LINQ query by using .AsSplitQuery() to avoid Cartesian explosion: context.Orders.Include(o => o.Details).AsSplitQuery().ToList();",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 WHERE 和 JOIN 子句使用的列上添加数据库索引。示例：CREATE INDEX IX_Orders_CustomerId ON Orders (CustomerId);",
    "在 OnConfiguring 中将 CommandTimeout 设置为更高值（如 120 秒）：optionsBuilder.UseSqlServer(connectionString, opts => opts.CommandTimeout(120));",
    "使用 .AsSplitQuery() 优化 LINQ 查询以避免笛卡尔爆炸：context.Orders.Include(o => o.Details).AsSplitQuery().ToList();"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlexception",
  "official_doc_section": null,
  "error_code": "-2146232060",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-06-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}