Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <p>The SQLite pooling code caches the connection using WeakReferences, which isn't the best <a href="https://stackoverflow.com/questions/930198/does-weakreference-make-a-good-cache">option</a> 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 <code>GC.Collect();</code> between closing one and opening another session, your test will always fail.</p> <p>My solution was to cache the connection myself between opening sessions, like this:</p> <pre><code>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); } } </code></pre> <p>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.</p> <p>I hope this helps you or anyone else who gets this error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload