Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add Retry Logic in NHibernate to handle Transient Failures in SQL Azure?

We have a .NET application that runs on Windows Azure and uses NHibernate to connect to a SQL Azure database. Sometimes it's necessary to add retry logic to handle transient failures in SQL Azure as described for example here -

http://social.technet.microsoft.com/wiki/contents/articles/retry-logic-for-transient-failures-in-sql-azure.aspx

Can someone point me to a way in doing this with NHibernate? Ideally I'd like to do this at the NHibernate level and not wrap every single call; I was able to do this for another ORM, .netTiers (http://nettiers.com) as I outline here -

http://blog.ehuna.org/2010/01/how_to_stop_getting_exceptions.html

I did search and found some answers that mention using a custom implementation of the IDbCommand interface -

Intercept SQL statements containing parameter values generated by NHibernate

But I'm not sure this works with NHibernate 3.2 and I'm looking for a clear example I could modify.

How could I make NHibernate retry calls to SQL Azure automatically? Let's say 3 retries, with 100ms wait between each - after the 3 retries, if still failing, we should throw the exception.

like image 987
ehuna Avatar asked Jan 08 '12 00:01

ehuna


2 Answers

I've released a library that takes care of this:

https://github.com/robdmoore/NHibernate.SqlAzure

like image 176
Robert Moore Avatar answered Oct 14 '22 21:10

Robert Moore


This is not a complete running example, but the files you need are here

https://github.com/craigvn/NHibernateRetryable

like image 31
Craig Avatar answered Oct 14 '22 22:10

Craig