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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:23:48+00:00 2026-05-23T22:23:48+00:00

So I am having an interesting issue with System.Data.SQLite and using multiple transactions. Basically

  • 0

So I am having an interesting issue with System.Data.SQLite and using multiple transactions. Basically I have the following code which fails:

using (IDbConnection connection1 = new SQLiteConnection("connectionstring"), connection2 = new SQLiteConnection("connectionstring"))
{
    connection1.Open();
    connection2.Open();

    IDbTransaction transaction1 = connection1.BeginTransaction();
    IDbTransaction transaction2 = connection2.BeginTransaction();    // Fails!

    using(IDbCommand command = new SQLiteCommand())
    {
        command.Text = "CREATE TABLE artist(artistid int, artistname text);";
        command.CommandType = CommandType.Text;
        command.Connection = connection1;
        command.ExecuteNonQuery();
    }

    using (IDbCommand command = new SQLiteCommand())
    {
        command.Text = "CREATE TABLE track(trackid int, trackname text);";
        command.CommandType = CommandType.Text;
        command.Connection = connection2;                    
        command.ExecuteNonQuery();
    }

    transaction1.Commit();
    transaction2.Commit();

}

From what I’ve read it seems that System.Data.SQLite should support nested and by extension sequential transactions. The code fails on line 7 (where the second transaction is declared) with the following exception:

System.Data.SQLite.SQLiteException: The database file is locked

System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
System.Data.SQLite.SQLiteDataReader.NextResult()
System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock)
System.Data.SQLite.SQLiteConnection.BeginDbTransaction(IsolationLevel isolationLevel)
System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()

Does anyone know what the issue is or how to get around this? I feel having concurrent transactions is essential for any database system so there must be some way to do this.

Thanks!

  • 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-23T22:23:50+00:00Added an answer on May 23, 2026 at 10:23 pm

    OP is initiating transactions on 2 connections, that’s where problems start, not multiple transactions per se.

    SQLiteConnection conn = new SQLiteConnection("data source=:memory:");
    conn.Open();
    
    var command = conn.CreateCommand();
    command.CommandText = "create table a (b integer primary key autoincrement, c text)";
    command.ExecuteNonQuery();
    
    var tran1 = conn.BeginTransaction();
    var tran2 = conn.BeginTransaction();
    
    var command1 = conn.CreateCommand();
    var command2 = conn.CreateCommand();
    
    command1.Transaction = tran1;
    command2.Transaction = tran2;
    
    command1.CommandText = "insert into a VALUES (NULL, 'bla1')";
    command2.CommandText = "insert into a VALUES (NULL, 'bla2')";
    
    command1.ExecuteNonQuery();
    command2.ExecuteNonQuery();
    
    tran1.Commit();
    tran2.Commit();
    
    command.CommandText = "select count(*) from a";
    Console.WriteLine(command.ExecuteScalar());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue querying Solr using the following field type: <fieldType name=text_ci class=solr.TextField
Folks, I'm having an interesting issue with Silverlight DataGrid data binding. It may be
Hey guys, I'm having an interesting issue, where I want to have a customized
i am having a internet / security issue with some code i have written.
I'm having an interesting issue when deploying an app to Tomcat. I'm using the
We have been having an interesting issue with the Eclipse update when some of
I am having an interesting problem with using pinvoke in C# to call _snwprintf.
Having an interesting issue. I'm reading from an excel file on a server via
Today I faced an interesting issue. I've been having an inheritance hierarchy with Hibernate
I am having trouble while using the YUI panel as a dialog. I have

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.