Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First and SQL Azure Connections

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:

  • http://blogs.msdn.com/b/sqlazure/archive/2010/05/11/10011247.aspx
  • http://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx
  • http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx
  • http://social.technet.microsoft.com/wiki/contents/articles/1541.aspx

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.

like image 293
Generic Error Avatar asked Dec 08 '25 03:12

Generic Error


1 Answers

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.

like image 94
Anže Vodovnik Avatar answered Dec 10 '25 17:12

Anže Vodovnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!