1

We are using Nhibernate to connect to a local firebird database file. We currently load it embedded but in some occasions need to release it so the file on disk can be moved or deleted. Simply closing and disposing the sessionfactory in nhibernate does not work. The file is still in use.

using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
{
    using (ISession session = sessionFactory.OpenSession())
    {
        using (System.Data.IDbCommand command = session.Connection.CreateCommand())
        {
            // commands removed
        }
    }

    sessionFactory.Close();
}

// file is still "in use" here

Is this possible to do or do we need to start a separate process?

Robert
  • 2,357
  • 4
  • 25
  • 46
  • 1
    I believe the Firebird .net provider pools connections, so you need to release the connections from the pool. – Mark Rotteveel Sep 01 '15 at 07:56
  • Thanks for the comment. I will try to change the release mode in nhibernate and see if that works. (http://nhibernate.info/doc/nh/en/index.html#transactions-connection-release) – Robert Sep 01 '15 at 10:12
  • Not sure if that is going to help, it is the Firebird driver itself that does the pooling. You could try to disable connection pooling (ie: add `Pooling=false` to the connection string). – Mark Rotteveel Sep 01 '15 at 10:41

1 Answers1

2

No need to disable pooling. I use NHibernate + FB Embedded in many projects of mine. Try FbConnection.ClearAllPools() at suitable point in your code (in your case it seems after you have finished using the session factory). You will need to add reference to the FB provider assembly in your project.

Vijay Gill
  • 1,508
  • 1
  • 14
  • 16