SQLite is trying to write a read-only database error

I have a console application that populates an SQLite database. When the application runs by itself, I get no errors. If I run multiple instances of the application, where each application is in its own folder, and each populates its own database, I sometimes get the following exception:

System.Data.SQLite.SQLiteException (0x80004005): Attempt to write a read-only database attempt to write a readonly 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() 

I know that the database is not only for reading, because it has already written data to this database. In addition, the application continues to work and will continue to populate data in this database. I did not reproduce the error when only one instance of the application is running.

I tried using pragma to have both a log and temp_store in memory, and not a file, if there was any conflict between applications, but I still get the error. I always get an error in the same method that is first inserted into the connection. To give a general idea of ​​what the application does, it covers all cases, collects information about these cases (not from SQLite), and then writes the results to the SQLite database.

I do not know what else to try.

* edit I also use PRAGMA journal_mode = MEMORY. When pasting data into a SQLite database, I first run the BEGIN statement, and then a bunch of inserts before the END statement. An error occurs on the first insert.

+8
c # sqlite sqlite3
source share
2 answers

This is a permissions issue.

Make sure that your web application that is hosted has the ability to add / write / create / delete access to the folder where the sqlite database is located.

For more information see this

+6
source share

It may also be that the database file is not supported by MigrationAssembly.

The same exception occurs when EF tries to migrate to a file, which is expected to be a SQLite database, which is fi. text file.

0
source share

All Articles