Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k 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());

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...