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 783523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:33:41+00:00 2026-05-14T20:33:41+00:00

What is the simplest most effective way to verify that your SQLite db is

  • 0

What is the simplest most effective way to verify that your SQLite db is actually out there after using NHib’s schema generation tool?

Cheers,
Berryl

EDIT

I am hoping there is something tied to the ISession (like the connection property) that can be tested; sometimes when running a series of tests it seems like a good session (IsOpen & IsConnected are true) but the db is not there (a query against it gets an error like ‘no such table’).

EDIT – WHAT I AM DOING NOW

Connection string & other cfg properties

public static Configuration GetSQLiteConfig()
    {
        return new Configuration()
            .SetProperty(ENV.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
            .SetProperty(ENV.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
            .SetProperty(ENV.ConnectionString, "Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1")
            .SetProperty(ENV.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
            .SetProperty(ENV.ReleaseConnections, "on_close")
            .SetProperty(ENV.CurrentSessionContextClass, typeof (ThreadStaticSessionContext).AssemblyQualifiedName);
    }

How I test the db now, for lack of something ‘better’ (this tests the mappings)

        public static void VerifyAllMappings(ISessionFactory sessionFactory, ISession session)
    {
        Check.RequireNotNull<ISessionFactory>(sessionFactory);
        Check.Require(session.IsOpen && session.IsConnected);

        _verifyMappings(sessionFactory, session);
    }

    private static void _verifyMappings(ISessionFactory sessionFactory, ISession session) {
        try {
            foreach (var entry in sessionFactory.GetAllClassMetadata())
            {
                session.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
                    .SetMaxResults(0).List();
            }
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
            throw;
        }
    }

        public static void VerifyAllMappings(ISessionFactory sessionFactory, ISession session)
    {
        Check.Require(!sessionFactory.IsClosed);
        Check.Require(session.IsOpen && session.IsConnected);

        try {
            foreach (var entry in sessionFactory.GetAllClassMetadata())
            {
                session.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
                    .SetMaxResults(0).List();
            }
        }
        catch (Exception ex) {
            Debug.WriteLine(ex);
            throw;
        }
    }

I generate the schema in a session provider whenever a new session is opened:

        public ISession Session
    {
        get
        {
            var session = (ISession)CallContext.GetData(_lookupSessionKey);
            try
            {
                if (session == null)
                {
                    _log.Debug("Opening new Session for this context.");

                    session = FactoryContext.Factory.OpenSession();

                    if(RunTypeBehaviorQualifier != RunType.Production)
                        SchemaManager.GenerateNewDb(FactoryContext.Cfg, session.Connection);
                    CallContext.SetData(_lookupSessionKey, session);
                }
            }
            catch (HibernateException ex)
            {
                throw new InfrastructureException(ex);
            }
            return session;
        }
    }

Now this is all probably way over engineered, but I need multiple database connections and I’ve been having trouble keeping it simpler & working. It’s also a lot of info for one question, but maybe someone else has actually got this all down to a science. The test below runs fine within it’s own test fixture, but not in conjunction with other tests.

    [Test]
    public void Schema_CanGenerateNewDbWithSchemaApplied()
    {
        DbMappingTestHelpers.VerifyAllMappings(_dbContext.FactoryContext.Factory, _dbContext.Session);
    }
  • 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-14T20:33:42+00:00Added an answer on May 14, 2026 at 8:33 pm

    Berryl,

    As far as I can see you’re strugling against mapped entities because you are using different connections. Is there any requirement that obligates you to use more than one “real” DB connection? I mean, can your tests share the same session (logically)? If not, you can simply configure your DB as:

          <property name="connection.connection_string">Data Source=NonTransactionalDB.txt;Version=3;New=True;Pooling=True;Max Pool Size=1;</property>
    

    The important part of it are the pooling options. As every session will aways use the same connection, you won’t have problems with recreating the schema everytime.

    It’s important to remeber, though, that it introduces to you some limitations about transactions. As SQLite can’t handle more than one transaction per connection, running your tests in parallel can bring you problems (something like a “database file is locked” Exception”).

    Cheers,

    Filipe

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

Sidebar

Related Questions

No related questions found

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.