Implementing Retry Policy using Data Access Application Block (Enterprise Library)
-
07 Ekim 2010 Perşembe 10:28
I have implemented the connectivity to SQL Azure using Enterprise Library 5.0. Which would be the best approach to implement the Retry Policy in to this implementation?
Thanks in Advance
Sreejith
Tüm Yanıtlar
-
08 Ekim 2010 Cuma 09:41Moderatör
Hi,
The usage of Enterprise Library is very like the usage of ADO.NET + strongly typed DataSet. To implement Retry, you need Try..Catch + a loop, just like the code mentioned below:
http://blogs.msdn.com/b/bartr/archive/2010/06/18/sql-azure-connection-retry.aspx
You may also put the retry logic in an extension method, which would make your code cleaner. For instance, you may write an extension method for UpdateDataSet method:
public static class Utility
{
public static int UpdateDataSetWithRetry(this Database db,int retrytimes)
{
int returnvalue = 0;
for (int i = 0; i < retrytimes; i++)
{
try
{
//...
// call db.UpdateDataSet() method
//...
}
catch (SqlException ex)
{
//...
}
catch (Exception ex)
{
// catch other exceptions if needed
}
}
return returnvalue;
}
}class Program
{
static void Main(string[] args)
{
Database db = DatabaseFactory.CreateDatabase();
//...// Retry 3 times if failed to update.
db.UpdateDataSetWithRetry(3);
}
}Learn more about extension method:
http://msdn.microsoft.com/en-us/library/bb383977.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Windows Azure Platform China Blog: http://blogs.msdn.com/azchina/default.aspx- Yanıt Olarak İşaretleyen Allen Chen - MSFTMicrosoft Employee, Moderator 14 Ekim 2010 Perşembe 08:29