Help Android Database Locked (code 5)

Asked

Viewed 675 times

0

I’m with an error Android Database Locked (code 5). I’ve tried all possible solutions found on Google and nothing solved. I have a Databasehelper class that has control of the bank’s connection and is extended by all classes that have transactions in the bank. Anyone 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) 
  • is closing the connection with the bank?

  • Yes, I am. I also use endTransaction for every transaction with the bank.

1 answer

0

So I recommend:

  • Make sure to close all instances of database helpers after you finish with them.

  • Ensure that you always finalize your transactions with endTransaction() also if you are unsuccessful (i.e., if you want to reverse them), if you use transactions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.