How to add Retry Logic to NHibernate to handle transient failures in SQL Azure?

We have a .NET application that runs on Windows Azure and uses NHibernate to connect to the Azure SQL database. Sometimes you need to add retry logic to handle transient failures in SQL Azure, as described here, for example,

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

Can someone tell me how to do this with NHibernate? Ideally, I would like to do this at the NHibernate level and not wrap every call; I was able to do this for another ORM, .netTiers ( http://nettiers.com ), as I will describe here -

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

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

Intercept SQL statements containing parameter values ​​generated by NHibernate

But I'm not sure if this works with NHibernate 3.2, and I'm looking for a clear example that I could change.

How can I get NHibernate to repeat Azure SQL calls automatically? Say 3 repetitions, with an expectation of 100 ms between them - after 3 attempts, if it still fails, we should throw an exception.

+6
source share
3 answers

I released a library that will take care of this:

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

+4
source

This is not a complete work example, but the files you need

https://github.com/craigvn/NHibernateRetryable

+2
source

Perhaps this may help you: http://www.objectreference.net/post/NHibernate-and-Execution-Plans.aspx . There is a class here that you can download and play with it, with some overrides.

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

I hope this helps anyway, I am going to a similar situation.

Hi,

+1
source

Source: https://habr.com/ru/post/905425/


All Articles