Answer the question
In order to leave comments, you need to log in
How to optimize work with the database when the error “The database file is locked” occurs?
Good afternoon!
When I started writing the project, I thought I would limit myself to a couple of connections to the SQLite database - load and save the settings, so I wrote connecting and closing the connection in a simplified way, right in the methods. Then the project grew and I thought "Well, okay, one more method, don't rewrite because of it..." ))
But such "well, one more" methods turned out to be as a result of dozens in one class, as a result, they seem to interfere each other during work and still have to rewrite.))
Yesterday the first bell rang - the project hung and gave the error "The database file is locked" on the next method.
I wrapped the call to the database in Invoke and everything worked. Today, a few more methods have been added, and each of them produces the same error.
The methods look something like this:
private void clearActive()
{
try
{
path = Application.dataPath + "/StreamingAssets/db.bytes";
scriptConnection.dbconnection = new SqliteConnection("URI=file:" + path);
scriptConnection.dbconnection.Open();
if (scriptConnection.dbconnection.State == ConnectionState.Open)
{
scriptConnection.cmd = new SqliteCommand();
scriptConnection.cmd.Connection = scriptConnection.dbconnection;
scriptConnection.cmd.CommandText = "UPDATE progress SET active = 0 WHERE active = 1";
scriptConnection.cmd.ExecuteNonQuery();
scriptConnection.dbconnection.Close();
}
else
{
Debug.Log("Error connection");
}
}
catch (Exception ex)
{
Debug.Log(ex);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question