Change SQLite database mode to read-write

2019-01-22 00:59发布

How can I change an SQLite database from read-only to read-write?

When I executed the update statement, I always got:

SQL error: attempt to write a readonly database

The SQLite file is a writeable file on the filesystem.

标签: sqlite3
14条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-22 01:36

In Linux command shell, I did:

chmod 777 <db_folder>

Where contains the database file.

It works. Now I can access my database and make insert queries.

查看更多
来,给爷笑一个
3楼-- · 2019-01-22 01:40

To share personal experience I encountered with this error that eventually fix both. Might not necessarily be related to your issue but it appears this error is so generic that it can be attributed to gazillion things.

  1. Database instance open in another application. My DB appeared to have been in a "locked" state so it transition to read only mode. I was able to track it down by stopping the a 2nd instance of the application sharing the DB.

  2. Directory tree permission - please be sure to ensure user account has permission not just at the file level but at the entire upper directory level all the way to / level.

Thanks

查看更多
做个烂人
4楼-- · 2019-01-22 01:41

I solved this by changing owner from root to me on all files on /db dir.

Just do ls -l on that folder, if any of the filer is owned by root just change it to you, using: sudo chown user file

查看更多
Melony?
5楼-- · 2019-01-22 01:42

If using Android.

Make sure you have added the permission to write to your EXTERNAL_STORAGE to your AndroidManifest.xml.

Add this line to your AndroidManifest.xml file above and outside your <application> tag.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

This will allow your application to write to the sdcard. This will help if your EXTERNAL_STORAGE is where you have stored your database on the device.

查看更多
你好瞎i
6楼-- · 2019-01-22 01:42

This error usually happens when your database is accessed by one application already, and you're trying to access it with another database.

查看更多
放荡不羁爱自由
7楼-- · 2019-01-22 01:42

From the command line, enter the folder where your database file is located and execute the following command:

chmod 777 databasefilename

This will grant all permissions to all users.

查看更多
登录 后发表回答