NHibernate : restore session connection after session lost

Posted by Catalin DICU on Stack Overflow See other posts from Stack Overflow or by Catalin DICU
Published on 2010-05-26T10:24:38Z Indexed on 2010/05/26 10:41 UTC
Read the original article Hit count: 780

Filed under:
|
|

I'm using NHibernate with SQL Server 2005 in a WPF client application.

If I stop the SQL Server service and then restart it the session doesn't automatically reconnect.

So far I'm doing this witch seems to work :

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 ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET