The general rule is this: Any time the session throws an exception, it is in an undefined state. The only thing you can safely do is Dispose() and handle the failure in your application. Either report the problem to the user or retry. Either way, you'll need to build a fresh session to continue using NHibernate.
As for your specific case, why are you restarting SQL with active users? That's a little BOFH of you. If it's really that important, you need to set up your application to handle this correctly (toss the whole session and start over). I'm not sure there's any fault tolerant setup that can actually redirect active, open database connections. On Wed, May 26, 2010 at 7:42 AM, Catalin DICU <[email protected]>wrote: > I'm using NHibernate with SQL Server 2005 in a WPF client application. > > If I manually stop the SQL Server service then restart it the session > doesn't automatically reconnect. > > So far this seems to work but is there a better/cleaner way ? : > > try > { > using (ITransaction transaction = this.Session.BeginTransaction()) > { > // some select here > } > }catch(Exception ex) > { > if(this.Session.Connection.State == ConnectionState.Closed) > { > try > { > this.Session.Connection.Open(); > } > catch (Exception) > { > } > } > } > > Is there a better way ? > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
