{
  "id": "dotnet/ef-core-sql-timeout-large-data",
  "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. The statement has been terminated.",
  "signature_zh": "Microsoft.Data.SqlClient.SqlException (0x80131904): 执行超时已过期。操作完成之前超时时间已到或服务器无响应。语句已终止。",
  "regex": "Microsoft\\.Data\\.SqlClient\\.SqlException \\(0x80131904\\): Execution Timeout Expired\\. The timeout period elapsed prior to completion of the operation or the server is not responding\\.",
  "domain": "dotnet",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "SQL query execution exceeds the configured command timeout, typically due to large data volumes, missing indexes, or inefficient LINQ queries generated by Entity Framework Core.",
  "root_cause_type": "generic",
  "root_cause_zh": "SQL 查询执行超过配置的命令超时时间，通常由大数据量、缺少索引或 Entity Framework Core 生成的低效 LINQ 查询引起。",
  "versions": [
    {
      "version": "6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing CommandTimeout to a very high value (e.g., 300 seconds) without optimizing the query",
      "why_fails": "Temporary fix that masks the underlying performance issue; query may still time out under heavy load or with larger datasets.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding .AsNoTracking() to all queries without understanding if tracking is needed",
      "why_fails": "AsNoTracking improves performance for read-only queries but does not fix inefficient joins or missing indexes.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Splitting the query into multiple smaller queries without using .Include() properly",
      "why_fails": "Multiple round trips can increase total execution time and cause N+1 query problems, worsening performance.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Optimize the LINQ query by adding .Where() filters early and using .Select() to project only needed columns. Example: var data = context.Orders.Where(o => o.Date > DateTime.UtcNow.AddDays(-30)).Select(o => new { o.Id, o.Total }).ToList();",
      "success_rate": 0.85,
      "how": "Optimize the LINQ query by adding .Where() filters early and using .Select() to project only needed columns. Example: var data = context.Orders.Where(o => o.Date > DateTime.UtcNow.AddDays(-30)).Select(o => new { o.Id, o.Total }).ToList();",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add database indexes on columns used in WHERE, JOIN, and ORDER BY clauses. Use SQL Server Management Studio or EF Core migrations: CREATE INDEX IX_Orders_Date ON Orders (Date);",
      "success_rate": 0.9,
      "how": "Add database indexes on columns used in WHERE, JOIN, and ORDER BY clauses. Use SQL Server Management Studio or EF Core migrations: CREATE INDEX IX_Orders_Date ON Orders (Date);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase CommandTimeout temporarily for the specific operation using: context.Database.SetCommandTimeout(120); or in connection string: \"Command Timeout=120;\"",
      "success_rate": 0.75,
      "how": "Increase CommandTimeout temporarily for the specific operation using: context.Database.SetCommandTimeout(120); or in connection string: \"Command Timeout=120;\"",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "通过早期添加 .Where() 过滤器和使用 .Select() 投影仅需要的列来优化 LINQ 查询。示例：var data = context.Orders.Where(o => o.Date > DateTime.UtcNow.AddDays(-30)).Select(o => new { o.Id, o.Total }).ToList();",
    "在 WHERE、JOIN 和 ORDER BY 子句中使用的列上添加数据库索引。使用 SQL Server Management Studio 或 EF Core 迁移：CREATE INDEX IX_Orders_Date ON Orders (Date);",
    "临时增加特定操作的 CommandTimeout：context.Database.SetCommandTimeout(120); 或在连接字符串中：\"Command Timeout=120;\""
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-2-database-engine-error",
  "official_doc_section": null,
  "error_code": "0x80131904",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.85,
  "resolvable": "partial",
  "first_seen": "2023-08-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}