Skip to content

Commit

Permalink
Add overload to SqlServerDbContextOptionsBuilder.EnableRetryOnFailure…
Browse files Browse the repository at this point in the history
… with errorNumbersToAdd without forcing maxRetryCount and maxRetryDelay

Fixes #27074
  • Loading branch information
Marusyk authored Jan 21, 2022
1 parent bb7c910 commit a482bd1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure()
public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure(int maxRetryCount)
=> ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c, maxRetryCount));

/// <summary>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// </summary>
/// <remarks>
/// <para>
/// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with
/// error numbers for transient errors that can be retried.
/// </para>
/// <para>
/// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used.
/// </para>
/// <para>
/// See <see href="https://aka.ms/efcore-docs-connection-resiliency">Connection resiliency and database retries</see>
/// for more information and examples.
/// </para>
/// </remarks>
/// <param name="errorNumbersToAdd">Additional SQL error numbers that should be considered transient.</param>
public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure(ICollection<int> errorNumbersToAdd)
=> ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c, errorNumbersToAdd));

/// <summary>
/// Configures the context to use the default retrying <see cref="IExecutionStrategy" />.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public SqlServerRetryingExecutionStrategy(
{
}

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </summary>
/// <remarks>
/// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used.
/// </remarks>
/// <param name="dependencies">Parameter object containing service dependencies.</param>
/// <param name="errorNumbersToAdd">Additional SQL error numbers that should be considered transient.</param>
public SqlServerRetryingExecutionStrategy(
ExecutionStrategyDependencies dependencies,
ICollection<int> errorNumbersToAdd)
: this(dependencies, DefaultMaxRetryCount, DefaultMaxDelay, errorNumbersToAdd)
{
}

/// <summary>
/// Creates a new instance of <see cref="SqlServerRetryingExecutionStrategy" />.
/// </summary>
Expand Down

0 comments on commit a482bd1

Please sign in to comment.