0 votes
1 view
in Azure by (33.1k points)

Could anyone guide me on how to implement a retry policy with EF to SQL Azure, please?

1 Answer

0 votes
by (16.8k points)

Add the binary, or the project in the link above to your solution, and add the reference to your project.

Instantiate a retry policy with suitable parameters:

    var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(

            10, 

            TimeSpan.FromSeconds(0.5), 

            TimeSpan.FromSeconds(2)

    ) { FastFirstRetry = true };

Use your retry policy object for any atomic work on the context.

    using(var context = new ... )

    {

        ...//Maybe you do something to the database...

        retryPolicy.ExecuteAction(() => context.SaveChanges());

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...