views:

55

answers:

1

Is there a way to ask NHibernate to automatically retry failed connections to a database? Specifically, if my network connection is too unreliable, sometimes NH will fail to connect to my remote SQL Server.

+2  A: 

Unless you're working with explicit "occasionally connected" requirements, the network should be reliable. I recommend fixing that instead of trying to make NHibernate work around something that should work in the first place.

That said, you might (just an idea) be able to get retries by overriding the connection driver's GenerateCommand() method. There you would return a wrapped IDbCommand that retries as necessary.

If you are working with "occasionally connected" requirements, see this question.

Mauricio Scheffer
We are working with what I'd like to call "usually connected" requirements -- a cellular connection on a bus that drives around and sometimes enters spotty cellular coverage. That question link is perfect though.
David Pfeffer
This is also a problem when working with SQL Server in a high availability environment. You need to be able to deal with the fact that the physical SQL server your connection is held too might go away in some sort of rollover scenario.
Nic Strong