Sometimes there is an exception thrown randomly:
"Some kind of disk I/O error occurred" or
"Unable to open database file"
After a long debugging I found out the problem occurs only if the journal_mode of SQLite is set to "DELETE" (which is default value). If I changed it e.g. to TRUNCATE it executes correctly.
So I have to use following statement as a workaround for initializing a datacontext:
Code: Select all
SQLiteConnection conn = new SQLiteConnection(_connectionString);
conn.Open();
MyDatabaseContext dbContext = new MyDatabaseContext(conn);
SQLiteCommand cmd = new SQLiteCommand("PRAGMA journal_mode = TRUNCATE", conn);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
return dbContext;