Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:33:42+00:00 2026-05-31T01:33:42+00:00

I’m writing an application for Windows Azure. I’m using Entity Framework to access SQL

  • 0

I’m writing an application for Windows Azure. I’m using Entity Framework to access SQL Azure. Due to throttling and other mechanisms in SQL Azure, I need to make sure that my code performs retries if an SQL statement has failed. I’m trying to come up with a solid method to do this.

(In the code below, ObjectSet returns my EFContext.CreateObjectSet())

Let’s say I have a function like this:

  public Product GetProductFromDB(int productID)
  {
     return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
  }

Now, this function performs no retries and will fail sooner or later in SQL Azure. A naive workaround would be to do something like this:

  public Product GetProductFromDB(int productID)
  {
     for (int i = 0; i < 3; i++)
     {
        try
        {
           return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
        }
        catch
        {

        }
     }
  }

Of course, this has several drawbacks. I will retry regardless of SQL failure (retry is waste of time if it’s a primary key violation for instance), I will retry immediately without any pause and so on.

My next step was to start using the Transient Fault Handling library from Microsoft. It contains RetryPolicy which allows me to separate the retry logic from the actual querying code:

  public Product GetProductFromDB(int productID)
  {
     var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(5);

     var result = _retryPolicy.ExecuteAction(() =>
        {
           return ObjectSet.Where(item => item.Id = productID).SingleOrDefault;
        });

     return result;
  }

The latest solution above is described as a http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx Best Practices for Handling Transient Conditions in SQL Azure Client Application (Advanced Usage Patterns section).

While this is a step forward, I still have to remember to use the RetryPolicy class whenever I want to access the database via Entity Framework. In a team of several persons, this is a thing which is easy to miss. Also, the code above is a bit messy in my opinion.

What I would like is a way to enforce that retries are always used, all the time. The Transient Fault Handling library contains a class called ReliableSQLConnection but I can’t find a way to use this with Entity Framework.

Any good suggestions to this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:33:43+00:00Added an answer on May 31, 2026 at 1:33 am

    After the above remarks, Microsoft created the transient fault handling library, which “includes direct support for working with SQL Azure through the ReliableSqlConnection class.”

    http://msdn.microsoft.com/en-us/library/hh680899(v=pandp.50).aspx

    Most developers looking to use Azure will find the above to be of great help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.