I am using the following code to update a “Picture” field in my SQLite database:
public void SetImage(byte[] image)
{
var sql = "UPDATE Part SET Picture=@0 WHERE PartId=" + PartId.ToString(CultureInfo.InvariantCulture);
var con = new SQLiteConnection(GetConnectionString());
var command = new SQLiteCommand(con)
{
CommandText = sql
};
command.Parameters.AddWithValue("@0", image);
con.Open();
command.ExecuteNonQuery();
con.Close();
command.Dispose();
con.Dispose();
}
All other data access to and from my SQLite database works fine. It just seems that when I try to insert data into this one field, it gives me an error “Database is locked”. My application is single threaded and all of my other data access functions properly close and dispose of the proper objects. Anyone have a clue what might be wrong?
The error “Database is locked” is likely to indicates that some other connection still has an open transaction.
Ensure that all commands and connections are properly closed and disposed.
To do that even in the case of exceptions, use
using.