3

Where can I find a sample of managing connection retries using SQL Azure and EF 4.1 Code First DbContext? I have found plenty of information on what I should be doing and why, here are some examples:

The trouble with these it they all refer to ObjectContext and I can't figure out how to make similar code work for my DbContext without upsetting EF.

1
  • 1
    I've created a library which allows you to configure Entity Framework to retry using the Fault Handling block without needing to change every database call - generally you will only need to change your config file and possibly one or two lines of code. This allows you to use it for Entity Framework or Linq To Sql. github.com/robdmoore/ReliableDbProvider Commented Jun 17, 2013 at 16:45

2 Answers 2

3

I am not that familliar with Code-first approach, but I do know you can instantiate the DbContext with a SQL Connection in the constructor, you could use Microsoft's Customer Advisory Reliable SQL Connection implementation. This connection has a Retry Policy that handles all the required retry logic you need.

Another option you can do, your implementation of the DbContext can implement the retry logic on each call. again, check out the CAT team's implementation on how to best do that.

Sign up to request clarification or add additional context in comments.

1 Comment

On a side note, you can have a look at their SQL Connection Factory implementation as well, as you'll see in the link to MSDN blog, you can specify the connection factory as well, which is an even better pattern if you don't want to manage your own connections.
0

The upcoming Entity Framework 6 release now includes built in support for connection resiliency, see here for more details:

http://blogs.msdn.com/b/adonet/archive/2013/08/21/ef6-release-candidate-available.aspx https://entityframework.codeplex.com/wikipage?title=Connection%20Resiliency%20Spec

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.