✅ SQLite Data Insert locks up database
I am working on a project of mine and I can get my application to create the database and its tables but when I try to insert the first set of data to populate the base data, it locks the database.
public static void PopulateDBVersionTable()
{
using SQLiteConnection sqliteConn = CreateConnection();
sqliteConn.Open();
using DbTransaction dbTrans = sqliteConn.BeginTransaction();
try
{
string sql = "Insert Into tblDBVersion (dbVersion, dbBuild) values (0,100)";
using (var command = new SQLiteCommand(sql, sqliteConn))
{
command.ExecuteNonQuery();
}
dbTrans.Commit();
}
catch (Exception ex)
{
dbTrans.Rollback();
MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (sqliteConn.State == ConnectionState.Open)
{
sqliteConn.Close();
}
}
}
Any help refactoring this so that it doesn't lock up on me would be great3 Replies
Define "lock up".
If you mean only one connection can write data, then... that's how SQLite works
Reading can be concurrent, but not writing
Each function is written like above, If I silence the other functions and only allow this one to run, I get a warning that the database is locked. If I silence this one and allow the rest to run, I don't get any errors
so the error must be in the function itselft but I can't find the cause.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.