I am currently trying to populate a SQLite database with tens of thousands of text data using this method:
SQLiteConnection = new SQLiteConnection(cntnStr);
connection.Open();
foreach(Page p in pages)
{
using (SQLiteCommand command = new SQLiteCommand(String.Format("Insert Into Pages (ID, Data, Name) Values ({0}, '{1}', '{2}')", id, p.Data, p.Name), connection))
command.ExecuteNonQuery();
}
However, I suspect that this is approximately 10 times per second, probably slowing down the whole process. Is there a way that I can collect data in memory and then add every 5000 records or so to the database in batch mode (so is it faster)?
EDIT: Super-important: make sure you run all your SQL commands in DbTransaction- in this case SQLiteTransaction:
SQLiteTransaction trans = connection.BeginTransaction();
trans.Commit();
This improves performance by 1000x.
source
share