SQLite 尝试写入只读数据库错误 [英] SQLite attempt to write a readonly database error
问题描述
我有一个填充 SQLite 数据库的控制台应用程序.当应用程序自行运行时,我没有收到任何错误.如果我运行应用程序的多个实例,其中每个应用程序都在自己的文件夹中,并且每个应用程序都填充自己的数据库,我偶尔会遇到以下异常:
I have a console application that populates a SQLite database. When the application runs by itself, I don't get any errors. If I run multiple instances of the application, where each application is in its own folder and each populates its own database I'll occasionally 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 the DB isn't read-only because it has already written data to that database. Also, the app continues on and will continue populating data to that database. I haven't reproduced the error when only a single instance of the application is running.
我已经尝试使用 pragma 将日志和 temp_store 都保存在内存中,而不是保存在文件中,以防其中的应用程序之间可能存在一些争用,但我仍然收到错误消息.我总是在相同的方法中得到错误,这是第一次为连接发生插入.为了大致了解应用程序的作用,它会遍历案例,收集有关这些案例的信息(不是来自 SQLite),然后将结果写入 SQLite 数据库.
I've tried using the pragma to have both the journal and temp_store in memory instead of to a file in case there could be some contention across applications there, but I still get the error. I do always get the error in the same method, which is the first time an insert would happen for the connection. To give a general idea of what the application does, it loops over cases, gathers info about those cases (not from SQLite), then writes results to the SQLite database.
我不知道还能尝试什么.
I don't know what else to try.
*编辑我也在使用 PRAGMA journal_mode=MEMORY.向SQLite数据库插入数据时,我先运行一个BEGIN语句,然后在END语句之前进行一堆插入.第一次插入时发生错误.
*edit I am also using the PRAGMA journal_mode=MEMORY. When inserting data into the SQLite database, I first run a BEGIN statement, then a bunch of inserts before the END statement. The error occurs on the first insert.
推荐答案
这是一个权限问题.
确保您托管的 Web 应用程序对 sqlite 数据库所在的文件夹具有添加/写入/创建/删除权限.
Make sure that your web application that is hosted has add/write/create/delete access to the folder where the sqlite database resides.
有关详细信息,请参阅此
这篇关于SQLite 尝试写入只读数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!