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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:33:22+00:00 2026-05-18T09:33:22+00:00

On my system, ~86000 SQLite insertions took up to 20 minutes, means ~70 insertions

  • 0

On my system, ~86000 SQLite insertions took up to 20 minutes, means ~70 insertions per second. I have to do millions, how can I speed up it? Calling Open() and Close() on SQLiteConnection object for every line can slow down performance? Can transactions help?

Typical insertion method for a single line:

public int InsertResultItem(string runTag, int topicId,
    string documentNumber, int rank, double score)
{
    // Apre la connessione e imposta il comando
    connection.Open();

    command.CommandText = "INSERT OR IGNORE INTO Result "
    + "(RunTag, TopicId, DocumentNumber, Rank, Score) " +
    "VALUES (@RunTag, @TopicId, @DocumentNumber, @Rank, @Score)";

    // Imposta i parametri
    command.Parameters.AddWithValue("@RunTag", runTag);
    command.Parameters.AddWithValue("@TopicId", topicId);
    command.Parameters.AddWithValue("@DocumentNumber", documentNumber);
    command.Parameters.AddWithValue("@Rank", rank);
    command.Parameters.AddWithValue("@Score", score);

    // Ottieni il risultato e chiudi la connessione
    int retval = command.ExecuteNonQuery();
    connection.Close();

    return retval;
}

As you can see, insertions are very simple ones.

  • 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-18T09:33:23+00:00Added an answer on May 18, 2026 at 9:33 am

    You definitely need a transaction. If you don’t, SQLite starts its own transaction for every insert command so you’re effectively doing 86000 transactions as is.

    It looks you’re also opening and closing the connection each time, along with resetting the CommandText each time. This is unnecessary and doubtless slowing you down, it’ll go much faster if you:

    • Open the connection once
    • Build the command once , adding the parameters to it once.
    • Start the transaction
    • Loop through, changing the parameter values only before calling ExecuteNonQuery
    • Commit the transaction.
    • Close the connection.

    I think you could reduce your 20 minutes down to just a few seconds this way.

    Edit: this is what I mean:

    public void InsertItems()
    {
        SQLiteConnection connection  = new SQLiteConnection(SomeConnectionString);
        SQLiteCommand command = connection.CreateCommand();
        SQLiteTransaction transaction = connection.BeginTransaction();
    
        command.CommandText = "INSERT OR IGNORE INTO Result "
    + "(RunTag, TopicId, DocumentNumber, Rank, Score) " +
      "VALUES (@RunTag, @TopicId, @DocumentNumber, @Rank, @Score)";
    
        command.Parameters.AddWithValue("@RunTag", "");
        command.Parameters.AddWithValue("@TopicId", "");
        command.Parameters.AddWithValue("@DocumentNumber", "");
        command.Parameters.AddWithValue("@Rank", "");
        command.Parameters.AddWithValue("@Score", "");
    
        foreach ( /* item to loop through and add to db */ )
        {
            InsertResultItem(runTag, topicId, documentNumber, rank, score, command);
        }
    
        transaction.Commit();
        command.Dispose();
        connection.Dispose();
    }
    
    public int InsertResultItem(string runTag, int topicId, string documentNumber, int rank, double score, SQLiteCommand command)
    {
        command.Parameters["@RunTag"].Value = runTag;
        command.Parameters["@TopicId"].Value = topicId;
        command.Parameters["@DocumentNumber"].Value = documentNumber;
        command.Parameters["@Rank"].Value = rank;
        command.Parameters["@Score"].Value = score;
        return command.ExecuteNonQuery();
    }
    

    It only uses one connection, one transaction and one command, so all you’re changing is the parameter values each time.

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

Sidebar

Related Questions

I have developed a referral system where logged in members can send referrals to
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
System: Windows XP SP3, .NET 3.5, 4GB RAM, Dual 1.6gHz I have a WPF
I have a PHP notification system, and the amount of notifications is put into
I have a table called user_logins which tracks user logins into the system. It
How can translate login page of my system by using this url: http://ip:8000/init/default/user/login display
I have a WCF service implemented using the WebServiceHostFactory (REST). I'm calling a service
I am developing a reservation system, and i have a function that save the
So I have this notification system that uses jQuery and PHP. The jQuery checks
I have a WCF server that I can run as a service or as

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.