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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:59:43+00:00 2026-06-11T00:59:43+00:00

I have a web application working with sqlite database. My version of sqlite is

  • 0

I have a web application working with sqlite database.
My version of sqlite is the latest from official windows binary distribution – 3.7.13.

The problem is that under heavy load on database, sqlite API functions (such as sqlite3_step) are returning SQLITE_BUSY.

I pass the following pragmas when initializing a connection:

journal_mode = WAL
page_size = 4096
synchronous = FULL
foreign_keys = on

The databas is one-file database. And I’m using Mono 2.10.8 and Mono.Data.Sqlite assembly provided with it to access database.

I’m testing it with 50 parallel threads which are sending 50 subsequent http-requests each to my application. On every request some reading and writing are done to the database. Every set of IO operations is executed inside the transaction.

Everything goes well until near 400th – 700th request. In this (random) moment API functions are starting to return SQLITE_BUSY permanently (To be more exact – until the limit of retries is reached).

As far as i know WAL mode transparently supports parallel reads and writes. I’ve guessed that it could be because of attempt to read database while checkpoint operation is executed. But even after turning autocheckpoint off the situation remains the same.

What could be wrong in this situation?
How to serve large amount of parallel database IO correctly?

P.S.

Only one connection per request is supposed.
I use nhibernate configured with WebSessionContext.

I initialize my NHibernate session like this:

ISession session = null;

//factory variable is session factory
if (CurrentSessionContext.HasBind(factory))
{
  session = factory.GetCurrentSession();
  if (session == null)
    CurrentSessionContext.Unbind(factory);
}

if (session == null)
{
  session = factory.OpenSession();
  CurrentSessionContext.Bind(session);
}

return session;

And on HttpApplication.EndRequest i release it like this:

//factory variable is session factory
if (CurrentSessionContext.HasBind(factory))
{
  try
  {
    CurrentSessionContext.Unbind(factory)
      .Dispose();
  }
  catch (Exception ee)
  {
    Logr.Error("Error uninitializing session", ee);
  }
}

So as far as i know there should be only one connection per request life cycle. While proceessing the request, code is executed sequentially (ASP.NET MVC 3). So it doesn’t look like any concurency is possible here. Can i conclude that no connections are shared in this case?

  • 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-06-11T00:59:45+00:00Added an answer on June 11, 2026 at 12:59 am

    It’s not clear to me if the request threads share the same connection or not. If they don’t then you should not be having these issues.

    Assuming that you are indeed sharing the connection object across multiple threads, you should use some locking mechanism as the the SqliteConnection isn’t thread-safe (an old post, but the SQLite library maintained as part of Mono evolved from System.Data.SQLite found on http://sqlite.phxsoftware.com).

    So assuming that you don’t lock around using the SqliteConnection object, can you please try it? A simple way to accomplish this could look like this:

    static readonly object _locker = new object();
    
    public void ProcessRequest()
    {
        lock (_locker) {
            using (IDbCommand dbcmd = conn.CreateCommand()) {
                string sql = "INSERT INTO foo VALUES ('bar')";
                dbcmd.CommandText = sql;
                dbcmd.ExecuteNonQuery();
            }
        }
    }
    

    You may however choose to open a distinct connection with each thread to ensure you don’t have any more threading issues with the SQLite library.

    EDIT

    Following-up on the code you posted, do you close the session after committing the transaction? If you don’t use some ITransaction, do you flush and close the session? I’m asking since I don’t see it in your code, and I see it mentioned in https://stackoverflow.com/a/43567/610650

    I also see it mentioned on http://nhibernate.info/doc/nh/en/index.html#session-configuration:

    Also note that you may call NHibernateHelper.GetCurrentSession(); as
    many times as you like, you will always get the current ISession of
    this HTTP request. You have to make sure the ISession is closed after
    your unit-of-work completes, either in Application_EndRequest event
    handler in your application class or in a HttpModule before the HTTP
    response is sent.

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

Sidebar

Related Questions

I have am working on a web application that makes use of helper classes.
I'm working on a web application that will have a custom UI for the
I'm working on a web application. I have entities that are supposed to be
I have a web application which was working well until I converted it from
I have an web application that I'm working on, it was working fine until
I have a web application and I am working on engine that analyzes referals.
I have a web application on java, which is working with database. I need
So, I have an odd problem. I'm working with an SQLite database through javascript
I have a web application that is working fine under the following environment GWT
I have a web application that is working great while running form VS, but

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.