Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this error message mean ? - sqlite3_exec - Failed to set synchronous mode = 1(Normal)

I am trying to open a SQLiteDatabase in a "Service" which fails with the following exception:

10-21 19:33:23.547: E/SqliteDatabaseCpp(31208): sqlite3_exec - Failed to set synchronous mode = 1(Normal) 
10-21 19:33:23.547: E/SQLiteDatabase(31208): Failed to open the database. closing it.
10-21 19:33:23.547: E/SQLiteDatabase(31208): android.database.sqlite.SQLiteDatabaseLockedException: database is locked
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1135)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1086)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1173)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:858)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:228)
10-21 19:33:23.547: E/SQLiteDatabase(31208):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)

Can somebody please explain what this means? and how can it be fixed?. The database is opened in the MainActivity and a Service.

like image 261
user1650281 Avatar asked Mar 10 '26 05:03

user1650281


1 Answers

I think it is an access conflict happened when the db was used (locked) by one thread (the activity?), the other thread (the service?) tried to use (lock) it but failed.

You can make your own SQLiteOpenHelper a singleton class, and then share it between the activity and service, and then the class will handle the conflict properly for you. See the discussion in this thread

like image 191
Ziteng Chen Avatar answered Mar 12 '26 17:03

Ziteng Chen