Reputation: 110510
Can you please help me understand why I am getting 'SQLiteException: database is locked' exception? In my content provider, I call in my Provider constructor
mDb = SQLiteDatabase.openDatabase(path, null, 0);
09-07 19:44:43.912 6830 6830 E AndroidRuntime: FATAL EXCEPTION: main
09-07 19:44:43.912 6830 6830 E AndroidRuntime: android.database.sqlite.SQLiteException: database is locked
09-07 19:44:43.912 6830 6830 E AndroidRuntime: at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
09-07 19:44:43.912 6830 6830 E AndroidRuntime: at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1990)
09-07 19:44:43.912 6830 6830 E AndroidRuntime: at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:905)
09-07 19:44:43.912 6830 6830 E AndroidRuntime: at com.mycompany.myapplication.provider.MyContentProvider.query(MyContentProvider.java:356)
Upvotes: 0
Views: 2525
Reputation: 10886
You are trying to open the database more than once at a time; which you cannot do.
I would recommend that your database handler class should be a singleton to prevent the possibility of having the database opened more than once.
An even better solution since you are on Android is to extend the SQLiteOpenHelper class. It will automatically make sure that database is only opened once and has helpful functions for initial creation and database updating.
Upvotes: 2
Reputation: 24140
database is locked exception will come if another database handler is looking the database. so make sure you are not looking database from another handler.
Upvotes: 0