Hi,
I use SQLite in a project, it works fine. But when i perform fast operations in a stress test (20.000 operation (insert, delete, select.. mixed) sequentially) i get this exception:
System.Data.SQLite.SQLiteException: Attempt to write a read-only database
at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
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.ExecuteNonQuery()
at System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock)
at System.Data.SQLite.SQLiteConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.SQLite.SQLiteConnection.BeginTransaction()
I use Database only from one process and i lock an object on all database operations like that:
public int RemoveMessage(int id)
{
lock (_syncObj)
{
return ExecuteNonQuery(
"DELETE FROM messages WHERE Id = @Id",
new SQLiteParameter("@Id", id)
);
}
}
So, only one process and one thread can access to database on a time. The only potential problem may be in connection string:
var csb = new SQLiteConnectionStringBuilder
{
DataSource = Path.Combine(GeneralHelper.GetCurrentDirectory(), @"SqliteDB\MDS.s3db"),
Version = 3,
Pooling = true,
ReadOnly = false,
SyncMode = SynchronizationModes.Off
};
ConnectionString = csb.ConnectionString;
I disabled Synchronization. Because if synchronization open i perform maximum 3-5 operations in a second, when sycnhronization is off, i perform 200 operations. I need performance in my project.
So, how i can solve this problem?