Retry Logic for Azure SQL in .NET: Handling Transient Errors Properly

Azure SQL Database can briefly interrupt connections during maintenance, scaling, or load balancing, so applications should expect short failures. Only transient errors, such as database unavailability during failover, service busy responses, and connection-level timeouts, should be retried, while errors like syntax issues or permission failures should not. Retries should use increasing delays with randomness to avoid overwhelming the service during an outage, and EF Core, Microsoft.Data.SqlClient, and libraries like Polly offer built-in ways to apply them. Transactions must be wrapped in an execution strategy so the entire unit retries together. Developers should also make writes idempotent, since a retry after a commit that was not acknowledged could otherwise create duplicate records.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in