# Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException: 执行策略 'SqlServerRetryingExecutionStrategy' 已执行操作 6 次但未成功。

- **ID:** `dotnet/ef-core-connection-resiliency-failed-to-retry`
- **领域:** dotnet
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Entity Framework Core 的重试执行策略因 SQL Server 的持久性瞬时故障（如死锁、超时或网络波动）而耗尽重试次数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Entity Framework Core 6.0.x | active | — | — |
| Entity Framework Core 7.0.x | active | — | — |
| Entity Framework Core 8.0.x | active | — | — |

## 解决方案

1. ```
   Analyze SQL Server error logs for deadlocks or timeouts; optimize queries or indexes to reduce contention.
   ```
2. ```
   Reduce retry interval and increase max retry count with exponential backoff in DbContext options.
   ```
3. ```
   Implement custom execution strategy to log and handle specific transient exceptions like deadlock (1205).
   ```

## 无效尝试

- **** — Increasing retry count without addressing root cause just delays failure. (90% 失败率)
- **** — Disabling retry entirely makes app brittle to transient faults. (95% 失败率)
- **** — Switching to a different execution strategy doesn't fix underlying database issues. (80% 失败率)
