When connecting 2 or more users to the same database I consistently get this error message. (This instance is when a thread is retrieving a configuration value, read-only operation.)
System.Data.SQLite.SQLiteException: The database file is locked
database is locked
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteScalar()
at XrefDatabaseConnection.GetXrefConfig(String config_name)
I've tried to shuffle around the different pragma values to allow for concurrent editing of a database file but nothing seems to work. Right now I have.
this.ExecuteNonQuery("PRAGMA cache_size = 32768");
this.ExecuteNonQuery("PRAGMA count_changes = 0");
this.ExecuteNonQuery("PRAGMA journal_mode = DELETE");
this.ExecuteNonQuery("PRAGMA read_uncommitted = 1");
this.ExecuteNonQuery("PRAGMA synchronous = NORMAL");
this.ExecuteNonQuery("PRAGMA temp_store = MEMORY");
// This ExecuteNonQuery is just an implementation that executes the query without creating the SQLCommand object directly. The function does that work for you.
I open the database with the following connection string.
Data Source={0};FailIfMissing=False;Legacy Format=False;Cache Size=16384;Page Size=32768; // Where {0} is the file name.
The file can and usually resides on a network path when I have concurrent users editing the file. Assume file permissions are set properly.
Also, I sometimes (very very rarely) have this problem when running the application itself and I suspect that it occurs because of a thread accessing the database. These threads do not write to the database! These threads that run are ran for short periods of time and clone the database connection rather than using the main thread's one. During my testing I've disabled all threads accessing the database and I still have problems when working with files on the network concurrently.
Lastly, the database access works similarly when working locally or on a network drive if 1 user is connected. It doesn't seem to matter.