7

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.

Community
  • 1
  • 1
ehuna
  • 111
  • 1
  • 6

3 Answers3

4

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

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

Robert Moore
  • 688
  • 5
  • 8
3

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

https://github.com/craigvn/NHibernateRetryable

Craig
  • 36,306
  • 34
  • 114
  • 197
1

Maybe this can help you out: http://www.objectreference.net/post/NHibernate-and-Execution-Plans.aspx. Here there is a class that you can download and play with it, with some overrides.

Also check this link as well: http://elliottjorgensen.com/nhibernate-api-ref/NHibernate.Driver/SqlClientDriver.html

I hope it helps in anyway, I'm going thru a similar situation.

Regards,

Carlos G.
  • 376
  • 2
  • 6