SQLiteDatabaseLockedException: database is locked Android Origin: On your device OSI layer 7 · Application Last updated 25 Nov 2026

android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)

Another connection holds a write lock on the SQLite database.

Exact message you may see SQLiteDatabaseLockedException database is lockedSQLITE_BUSY database is lockeddatabase is locked code 5android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY): , while compiling: PRAGMA journal_mode
Seen on: Android Kotlin

Meaning

Concurrent writers collide. Use one database instance, enable WAL mode, keep transactions short and avoid opening several helpers for the same file.

Common causes

  • Multiple SQLiteOpenHelper instances
  • Long write transaction
  • Writes from several processes

⚡ Quick fix

  1. Use a singleton database
  2. Enable WAL (Room does by default)
  3. Shorten transactions

Detailed fix by platform

Kotlin

  1. Room.databaseBuilder(ctx, Db::class.java, "app.db").setJournalMode(JournalMode.WRITE_AHEAD_LOGGING).build()

How to diagnose

  1. Instances — one?
  2. WAL — enabled?
  3. Processes — how many?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot access database on the main thread — Room: Cannot access database on the main thread since it may potentially lock the UI for a long period of time (Android)Cannot access databas…CorruptionException: Unable to parse preferences proto — androidx.datastore.core.CorruptionException: Unable to parse preferences proto (Android)CorruptionException: …CursorWindow: Window is full: requested allocation bytes — android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed (Android)CursorWindow: Window …IllegalStateException: A migration from 1 to 2 was required but not found — java.lang.IllegalStateException: A migration from 1 to 2 was required but not found. Please provide the necessary Migration path (Android)IllegalStateException…IllegalStateException: Cannot perform this operation because the connection pool has been closed — java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase (Android)IllegalStateException…KSP: processor not found / unresolved reference to generated class — [ksp] Unresolved reference: AppDatabase_Impl (Android)KSP: processor not fo…Room: An entity must have at least 1 field annotated with @PrimaryKey — error: An entity must have at least 1 field annotated with @PrimaryKey (Android)Room: An entity must …Room: Cannot figure out how to save this field into database — error: Cannot figure out how to save this field into database. You can consider adding a type converter for it. (Android)Room: Cannot figure o…SQLiteDat…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.