Communication errors are always a pain!! When you are working
with cloud platform like Azure, communication errors makes you feel the pain
even more!!
Thanks that Transient Fault Handling framework exists!!
Alright guys, so here I am going demonstrate how to configure
transient fault handling application block of Enterprise Library 6 (and above
hopefully, if they don’t change in next versionsJ) with
SQL Azure and Entity framework. This going to be a long article that is what I
think. So be ready!!
What are
Transient Faults or Transient Errors?
These are mainly network issues. If you perform an operation
in Azure and sometimes it does not work however if you try after some time, it
works well. This odd and non-predictable behavior is nothing but transient
faults.
When we talk about SQL Azure, transient faults are common. The
article Azure SQL Database
Resource Management - http://msdn.microsoft.com/library/azure/dn338083.aspx mentions the scenarios in which
you may face transient fault of SQL Azure. I highly recommend you to go through the all
this documents and related links. Very informative!!
Now, very common transient error of SQL Azure is throttling.
What is
throttling?
Throttle is very common term used in computing and networking.
The dictionary meaning of throttle is to kill or stop something. Throttling can
be of any type like, network throttling, bandwidth throttling, and email
throttling and so on. Throttling can be
sometime good and sometime bad. When it is bad for you, it is your
responsibility to handle it. Throttling is good when the database server engine
is experiencing extreme load and it is well above the desired load. Then throttling
brings down consumption of resource and frees some of the load of database
engine. This is done via blocking the connections or denying the new
connections to SQL Azure database engine. It is bad when you are trying to
connect to SQL Azure and throttling occurs and you get connectivity errors with
SQL Azure. To understand more about SQL Azure throttling refer to the link - http://msdn.microsoft.com/en-US/library/azure/dn338079.aspx.
Solution
-
The solution is simple and you are advised to implement retry
logic in your application. To implement retry logic in SQL Azure and entity
framework, we use Transient Fault Handling block. It is simple and recommended
to always use Transient Fault Handling framework to deal with SQL Azure
connectivity errors and have retry logic in application.
Implementation
–
Please
note that, I am using Transient Fault Handling Block version 6.0.1304. This is
the one available as of today (7th July 2014). Also I am using Azure
SDK 2.3 and visual stiudio 2013 for this sample.
First
let’s create a server in SQL Azure and add a database in it. I created simple
database named as Company and added only one table in it named as Customer with
3 columns and sample data as shown in below screenshot.