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

  • SEARCH
  • Home
  • 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 7009695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:41+00:00 2026-05-27T21:53:41+00:00

I have a system which after getting a message – enqueues it (write to

  • 0

I have a system which after getting a message – enqueues it (write to a table), and another process polls the DB and dequeues it for processing. In my automatic tests I’ve merged the operations in the same process, but cannot (conceptually) merge the NH sessions from the two operations.

Naturally – problems arise.

I’ve read everything I could about getting the SQLite-InMemory-NHibernate combination to work in the testing world, but I’ve now ran into RANDOMLY failing tests, due to “no such table” errors. To make it clear – “random” means that the same test with the same exact configuration and code will sometimes fail.

I have the following SQLite configuration:

return SQLiteConfiguration
 .Standard
 .ConnectionString(x => x.Is("Data Source=:memory:; Version=3; New=True; Pooling=True; Max Pool Size=1;"))
 .Raw(NHibernate.Cfg.Environment.ReleaseConnections, "on_close");

At the beginning of my test (every test) I fetch the “static” session provider, and kindly ask it to flush the existing DB clean, and recreate the schema:

public void PurgeDatabaseOrCreateNew()
{
    using (var session = GetNewSession())
    using (var tx = session.BeginTransaction())
    {
            PurgeDatabaseOrCreateNew(session);
            tx.Commit();
    }
}

private void PurgeDatabaseOrCreateNew(ISession session)
{
    //http://ayende.com/Blog/archive/2009/04/28/nhibernate-unit-testing.aspx
    new SchemaExport(_Configuration)
        .Execute(false, true, false, session.Connection, null);
}

So yes, it’s on a different session, but the connection is pooled on SQLite, so the next session I create will see the generated schema. Yet, while most of the times it works – sometimes the later “enqueue” operation will fail because it cannot see a table for my incoming messages.
Also – that seems to happen at max one or twice per test suite run; not all the tests are failing, just the first one (and sometimes another one. Not quite sure if it’s the second or not).

The worst part is the randomness, naturally. I’ve told myself I’ve fixed this several times now, just because it simply “stopped failing”. At random.

This happens on FW4.0, System.Data.SQLite x86 version, Win7 64b and 2008R2 (three differen machine in total), NH2.1.2, configured with FNH, on TestDriven.NET 32b precesses and NUnit console 32b processes.

Help?

  • 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. Editorial Team
    Editorial Team
    2026-05-27T21:53:42+00:00Added an answer on May 27, 2026 at 9:53 pm

    Hi I’m pretty sure I have the exact same problem as you. I open and close multiple sessions per integration test. After digging through the SQLite connection pooling and some experimenting of my own, I’ve come to the following conclusion:

    The SQLite pooling code caches the connection using WeakReferences, which isn’t the best option for caching, since the reference to the connection(s) will be cleared when there is no normal (strong) reference to the connection and the GC runs. Since you can’t predict when the GC runs, this explains the “randomness”. Try and add a GC.Collect(); between closing one and opening another session, your test will always fail.

    My solution was to cache the connection myself between opening sessions, like this:

    public class BaseIntegrationTest
    {
        private static ISessionFactory _sessionFactory;
        private static Configuration _configuration;
        private static SchemaExport _schemaExport;
    
        // I cache the whole session because I don't want it and the
        // underlying connection to get closed.
        // The "Connection" property of the ISession is what we actually want.
        // Using the NHibernate SQLite Driver to get the connection would probably
        // work too.
        private static ISession _keepConnectionAlive;
    
        static BaseIntegrationTest()
        {
            _configuration = new Configuration();
            _configuration.Configure();
            _configuration.AddAssembly(typeof(Product).Assembly);
            _sessionFactory = _configuration.BuildSessionFactory();
            _schemaExport = new SchemaExport(_configuration);
    
            _keepConnectionAlive = _sessionFactory.OpenSession();
        }
    
        [SetUp]
        protected void RecreateDB()
        {
            _schemaExport.Execute(false, true, false, _keepConnectionAlive.Connection, null);
        }
    
        protected ISession OpenSession()
        {
            return _sessionFactory.OpenSession(_keepConnectionAlive.Connection);
        }
    }
    

    Each of my integrationtests inherits from this class, and calls OpenSession() to get a session. RecreateDB is called by NUnit before each test because of the [SetUp] attribute.

    I hope this helps you or anyone else who gets this error.

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

Sidebar

Related Questions

I have build a catalog system which use SQL CE as database. After deploying
I have a system which sits on a web server and generates files on
I have a system which is writing files to a folder using FTP. I
I have a system which is receiving log files from different places through http
I have a system which contains multiple applications connected together using JMS and Spring
I have a web system which has a classical parent-children menu saved in a
I have a system in which different server processes are handling requests passed as
I have a current system which is build as a Windows Application, and does
I have a logger system which basically is a fancy way of writing my
We are an organisation who have purchased a system which is used by doctors

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.