# System.InvalidOperationException: An error occurred while executing the query. The query has been canceled. See InnerException for details. -> Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

- **ID:** `dotnet/ef-core-query-split-query-timeout`
- **Domain:** dotnet
- **Category:** data_error
- **Error Code:** `0x80131904`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Entity Framework Core's split query mode (enabled via AsSplitQuery()) generates multiple SQL queries that execute sequentially, and the total time exceeds the default 30-second command timeout, especially with large datasets or multiple includes.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| EF Core 5.0 | active | — | — |
| EF Core 6.0 | active | — | — |
| EF Core 7.0 | active | — | — |
| EF Core 8.0 | active | — | — |
| SQL Server 2016+ | active | — | — |

## Workarounds

1. **Increase the command timeout specifically for the problematic query using .CommandTimeout(120) on the DbContext or query-level.** (80% success)
   ```
   Increase the command timeout specifically for the problematic query using .CommandTimeout(120) on the DbContext or query-level.
   ```
2. **Optimize the query by reducing the number of Includes, using explicit loading, or batching data retrieval with multiple queries.** (90% success)
   ```
   Optimize the query by reducing the number of Includes, using explicit loading, or batching data retrieval with multiple queries.
   ```

## Dead Ends

- **Removing AsSplitQuery() and relying on single query with joins, which may cause cartesian explosion** — Single queries with many Includes can result in huge result sets and memory pressure, leading to different performance issues. (50% fail)
- **Setting CommandTimeout to a very high value (e.g., 5 minutes) globally in DbContext options** — This masks the underlying performance issue and may cause other queries to hang indefinitely. (20% fail)
