Could anyone guide me how to implement a retry policy with EF to SQL Azure, please.
I am using the Transiet Fault Handling Framework, provided in lue of a better solution by EF team.
var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(
10,
TimeSpan.FromSeconds(0.5),
TimeSpan.FromSeconds(2)
) { FastFirstRetry = true };
context
. using(var context = new ... )
{
...//Maybe you do something to the database...
retryPolicy.ExecuteAction(() => context.SaveChanges());
}
Entity Framework 6 has added connection resiliency as a new feature to help address this, quoting from Microsoft: "enables automatic recovery from transient connection failures". Here is the Connection Resiliency Spec for EF6 if you want to learn more.
EF6 at NuGet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With