Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:27:32+00:00 2026-05-11T10:27:32+00:00

Background: My team is dedicated to ensuring that straight from checkout, our code compiles

  • 0

Background:

My team is dedicated to ensuring that straight from checkout, our code compiles and unit tests run successfully. To facilitate this and test some of our NHibernate mappings, we’ve added a SQLite DB to our repository which is a mirror of our production SQL Server 2005 database. We’re using the latest versions of: MbUnit3 (part of Gallio), System.Data.SQLite and NHibernate.

Problem:

I’ve discovered that the following unit test does not work with SQLite, despite executing without trouble against SQL Server 2005.

    [Test]     [Rollback]     public void CompleteCanPersistNode()     {         // returns a Configuration for either SQLite or SQL Server 2005 depending on how the project is configured.         Configuration config = GetDbConfig();           ISessionFactory sessionFactory = config.BuildSessionFactory();         ISession session = sessionFactory.OpenSession();          Node node = new Node();         node.Name = 'Test Node';         node.PhysicalNodeType = session.Get<NodeType>(1);          // SQLite fails with the exception below after the next line called.         node.NodeLocation = session.Get<NodeLocation>(2);          session.Save(node);         session.Flush();          Assert.AreNotEqual(-1, node.NodeID);         Assert.IsNotNull(session.Get<Node>(node.NodeID));     } 

The exception I’m getting (ONLY when working with SQLite) follows:

 NHibernate.ADOException: cannot open connection ---> System.Data.SQLite.SQLiteException:   The database file is locked database is locked     at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)     at System.Data.SQLite.SQLiteDataReader.NextResult()     at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)     at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)     at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()     at System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock)     at System.Data.SQLite.SQLiteConnection.BeginDbTransaction(IsolationLevel isolationLevel)     at System.Data.SQLite.SQLiteConnection.BeginTransaction()     at System.Data.SQLite.SQLiteEnlistment..ctor(SQLiteConnection cnn, Transaction scope)     at System.Data.SQLite.SQLiteConnection.EnlistTransaction(Transaction transaction)     at System.Data.SQLite.SQLiteConnection.Open()     at NHibernate.Connection.DriverConnectionProvider.GetConnection()     at NHibernate.Impl.SessionFactoryImpl.OpenConnection()     --- End of inner exception stack trace ---     at NHibernate.Impl.SessionFactoryImpl.OpenConnection()     at NHibernate.AdoNet.ConnectionManager.GetConnection()     at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd)     at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)     at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)     at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)     at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)     at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister)     at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)     at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session)     at NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)     at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)     at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)     at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)     at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)     at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)     at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)     at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)     at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)     at NHibernate.Impl.SessionImpl.Get[T](Object id) D:\dev\598\Code\test\unit\DataAccess.Test\NHibernatePersistenceTests.cs 

When SQLite is used and the [Rollback] attribute is NOT specified, the test also completes successfully.

Question:

Is this an issue with System.Data.SQLite’s implementation of TransactionScope which MbUnit3 uses for [Rollback] or a limitation of the SQLite engine?

Is there some way to write this unit test, working against SQLite, that will rollback so as to avoid affecting the database each time the test is run?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:27:33+00:00Added an answer on May 11, 2026 at 10:27 am

    Check if you’re not missing connection.release_mode=on_close in your SQLite NHibernate configuration. (reference docs)

    BTW: always dispose your ISession and ISessionFactory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you have a serie of images you want to… May 11, 2026 at 3:51 pm
  • added an answer Joomla is PHP based whereas Google App Engine is Python… May 11, 2026 at 3:51 pm
  • added an answer There are three types of standards behaviour you should be… May 11, 2026 at 3:51 pm

Related Questions

As the title suggests, I would like to see if this is something people
My team is working on a crappy old website and most of the pages
My team works mostly w/ Flex-based applications. That being said, there are nearly no
I am working in the web dept of a large legal firm, and among

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.