Help Android Database Locked (code 5)

0

I'm having an Android Database Locked error (code 5). I've tried all the possible solutions found in Google and nothing solved. I have a DatabaseHelper class that has the database connection control and is extended by all classes that have transactions in the database. Someone can help.

E/SQLiteLog: (5) database is locked

E/SQLiteDatabase: Failed to open database '/mnt/expand/b680bba9-efa7-4c00-ba72-2ed18d19f908/user/0/br.com.mercosoft.pedidos/databases/pedidos.db'.
              android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
                  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                  at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
                  at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320)
                  at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
                  at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
                  at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                  at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                  at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                  at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                  at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
                  at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
                  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
                  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:652)
                  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
                  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                  at br.com.mercosoft.pedidos.model.ConfigDAO.<init>(ConfigDAO.java:26)
                  at br.com.mercosoft.pedidos.Principal.onCreate(Principal.java:77)
                  at android.app.Activity.performCreate(Activity.java:6687)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6165)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: br.com.mercosoft.pedidos, PID: 23056
              java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.mercosoft.pedidos/br.com.mercosoft.pedidos.Principal}: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6165)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
               Caused by: android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
                  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                  at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
                  at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320)
                  at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
                  at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
                  at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                  at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                  at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                  at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                  at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
                  at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
                  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
                  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:652)
                  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
                  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                  at br.com.mercosoft.pedidos.model.ConfigDAO.<init>(ConfigDAO.java:26)
                  at br.com.mercosoft.pedidos.Principal.onCreate(Principal.java:77)
                  at android.app.Activity.performCreate(Activity.java:6687)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6165) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) 
    
asked by anonymous 01.06.2018 / 19:42

1 answer

0

So, I recommend:

  • Be sure to close all instances of database helpers after you have finished with them.

  • Ensure that you always end transactions with endTransaction() also if you do not succeed (ie, if you want to reverse them) if you use transactions

01.06.2018 / 20:47