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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:39:05+00:00 2026-06-08T06:39:05+00:00

I am using an SQLite database, and inserting records into it. This takes a

  • 0

I am using an SQLite database, and inserting records into it. This takes a hugely long time! I have seen people who say they can process a couple thousand in a minute. I have around 2400 records. Each record takes 30s-2m to complete. Recreating the database is not an option. I have tried to create one transaction different ways. I need to use the timer, because I am using a ProgressBar to show me that something is happening. Here is the code I am using:

string con;
con = string.Format(@"Data Source={0}", documentsFolder);

SQLiteConnection sqlconnection = new SQLiteConnection(con);
SQLiteCommand sqlComm = sqlconnection.CreateCommand();
sqlconnection.Open();
SQLiteTransaction transaction = sqlconnection.BeginTransaction();

Timer timer2 = new Timer();
timer2.Interval = 1000;
timer2.Tick += (source, e) =>
                    {
                        URL u = firefox.URLs[count2];
                        string newtitle = u.title;
                        form.label1.Text = count2 + "/" + pBar.Maximum;
                        string c_urls = "insert or ignore into " + table + " (id,
 url, title, visit_count, typed_count, last_visit_time, hidden) values (" + dbID + ",'" + u.url + "','" 
    + newtitle + "',1,1, " + ToChromeTime(u.visited) + ", 0)";
                        string c_visited = "insert or ignore into " + table2 + " (id,
 url, 
    visit_time, transition) values (" + dbID2 + "," + dbID + "," + 
ToChromeTime(u.visited) + ",805306368)";
                        sqlComm = new SQLiteCommand(c_urls, sqlconnection);
                        sqlComm.ExecuteNonQuery();
                        sqlComm = new SQLiteCommand(c_visited, sqlconnection);
                        sqlComm.ExecuteNonQuery();

                        dbID++;
                        dbID2++;


                        pBar.Value = count2;
                        if (pBar.Maximum == count2)
                        {
                            pBar.Value = 0;
                            timer.Stop();
                            transaction.Commit();
                            sqlComm.Dispose();
                            sqlconnection.Dispose();
                            sqlconnection.Close();
                        }

                        count2++;
                    };
timer2.Start();

What am I doing wrong?

  • 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-08T06:39:07+00:00Added an answer on June 8, 2026 at 6:39 am

    This is what I would address, in order. It may or may not fix the problem, but it won’t hurt to see (and it might just do some magic):

    1. Ensure the Database is not being contended with updates (from another thread, process, or even timer!). Writers will acquire locks and unclosed/over-long-running transactions can interact in bad ways. (For updates that take “30 seconds to 2 minutes” I would imagine there is an issue obtaining locks. Also ensure the media the DB is on is sufficient, e.g. local drive.)

    2. The transaction is not being used (??). Move the transaction inside the timer callback, attach it to the appropriate SQLCommands, and dispose it before the callback ends. (Use using).

    3. Not all SQLCommand’s are being disposed correctly. Dispose each and every one. (The use of using simplifies this. Do not let it bleed past the callback.)

    4. Placeholders are not being used. Not only is this simpler and easier to use, but it is also ever so slightly more friendly to SQLite and the adapter.

    (Example only; there may be errors in the following code.)

    // It's okay to keep long-running SQLite connections.
    // In my applications I have a single application-wide connection.
    // The more important thing is watching thread-access and transactions.
    // In any case, we can keep this here.
    SQLiteConnection sqlconnection = new SQLiteConnection(con);
    sqlconnection.Open();
    
    // In timer event - remember this is on the /UI/ thread.
    // DO NOT ALLOW CROSS-THREAD ACCESS TO THE SAME SQLite CONNECTION.
    // (You have been warned.)
    URL u = firefox.URLs[count2];
    string newtitle = u.title;
    form.label1.Text = count2 + "/" + pBar.Maximum;
    
    try {
       // This transaction is ONLY kept about for this timer callback.
       // Great care must be taken with long-running transactions in SQLite.
       // SQLite does not have good support for (long running) concurrent-writers
       // because it must obtain exclusive file locks.
       // There is no Table/Row locks!
       sqlconnection.BeginTransaction();
       // using ensures cmd will be Disposed as appropriate.
       using (var cmd = sqlconnection.CreateCommand()) {
         // Using placeholders is cleaner. It shouldn't be an issue to
         // re-create the SQLCommand because it can be cached in the adapter/driver
         // (although I could be wrong on this, anyway, it's not "this issue" here).
         cmd.CommandText = "insert or ignore into " + table
           + " (id, url, title, visit_count, typed_count, last_visit_time, hidden)"
           + " values (@dbID, @url, 'etc, add other parameters')";
         // Add each parameter; easy-peasy
         cmd.Parameters.Add("@dbID", dbID);
         cmd.Parameter.Add("@url", u.url);
         // .. add other parameters
         cmd.ExecuteNonQuery();
       }
       // Do same for other command (runs in the same TX)
       // Then commit TX
       sqlconnection.Commit();
    } catch (Exception ex) {
       // Or fail TX and propagate exception ..
       sqlconnection.Rollback();
       throw;
    }
    
    if (pBar.Maximum == count2)
    {
        pBar.Value = 0;
        timer.Stop();
        // All the other SQLite resources are already
        // cleaned up!
        sqlconnection.Dispose();
        sqlconnection.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to insert 8000+ records into a SQLite database using Django's ORM. This
I have a problem with inserting data into SQLite database using QSqlTableModel. The table
I was newbie in using sqlite database android. and now I have a problem
I have a SQLite DB designed using SQLite Database Browser 2.0 b1 I have
I have been working with iPhone application in which i am using sqlite database.
I am using the Sqlite Database in my Application, I have already upload my
I'm creating a DB using SQLite from .NET and then inserting 1500 records (15
I am trying to insert a data into SQLite database using Python. INSERT INTO
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I'm using a SQLite database to store cover images of books I have in

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.