I have an app that use collections of objects an is really fast. Now, I am adding a database for persitancy, so I started to save things in SQLite database.
But now i found is much much slowly. I think it is because the disk is slower than ram. it possible to have the DB in memory? I found an Inmemory DB in the documentation of SQLite, but it is in memory and I need persitancy.
So, is it possible to have the DB in memory for perfoamnce and save to the disk after some time?
Thank you and regards.
Update:
In the answers they say that it is because I am doing lots of inserts, and this is true. They say I should make a bulk insert.
My code looks like this in a memory collection called Computers:
foreach (line in lines)
{
Computers.Add(new Computer { ComputerName = line});
}
Now in the DB:
foreach (line in lines)
{
string sql = "INSERT into computers VALUES ('"+computerName+"')";
SQLiteCommand command = new SQLiteCommand(sql, dbConnection); command.ExecuteNonQuery();
}
How can I do this in a single bulk insert?