Search code examples
c#nhibernatefirebirdfirebird2.5firebird-embedded

How to release database file? (NHibernate and embedded Firebird database)


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?


Solution

  • 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.