title: How do I add Retry Logic in NHibernate to handle Transient Failures in SQL Azure?
body: <p>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 -</p>
  
  <p><a href="http://social.technet.microsoft.com/wiki/contents/articles/retry-logic-for-transient-failures-in-sql-azure.aspx" rel="nofollow noreferrer">http://social.technet.microsoft.com/wiki/contents/articles/retry-logic-for-transient-failures-in-sql-azure.aspx</a></p>
  
  <p>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 (<a href="http://nettiers.com" rel="nofollow noreferrer">http://nettiers.com</a>) as I outline here -</p>
  
  <p><a href="http://blog.ehuna.org/2010/01/how_to_stop_getting_exceptions.html" rel="nofollow noreferrer">http://blog.ehuna.org/2010/01/how_to_stop_getting_exceptions.html</a></p>
  
  <p>I did search and found some answers that mention using a custom implementation of the IDbCommand interface -</p>
  
  <p><a href="https://stackoverflow.com/questions/6048835/intercept-sql-statements-containing-parameter-values-generated-by-nhibernate">Intercept SQL statements containing parameter values generated by NHibernate</a></p>
  
  <p>But I'm not sure this works with NHibernate 3.2 and I'm looking for a clear example I could modify.</p>
  
  <p>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.</p>