tags:

views:

63

answers:

1

Hi guys,

I wonder if Nihbernate close db connection supplied as a parameter to OpenSession method.

Example

using(var session = sessionFactory.OpenSession(connection)) {

}

I want connection to be disposed with the session.

Best regards, Alexey Zakharov

A: 

I solved my problem with customized DriverConnectionProvider

public class TenantConnectionProvider : DriverConnectionProvider
{
    public override IDbConnection GetConnection()
    {
        IDbConnection conn = Driver.CreateConnection();
        try
        {
            conn.ConnectionString = // Tenant connection string provider called here
            conn.Open();
        }
        catch (Exception)
        {
            conn.Dispose();
            throw;
        }

        return conn;


   }
}

In this case I may use OpenSession method without supplying connection string as parameter.

Alexey Zakharov
Hi Alexey, you didn't really answer your own question :-) "Does NHibernate close the DB connection passed to the Session constructor?" So: does it?
Oliver