Database Locked Error Code 5


#1

I get database lock error most of the times… ! what all the cases that lead to database lock.

Error inserting redacted values> into Medicinemaster
net.sqlcipher.database.SQLiteException: error code 5: database is locked


Error inserting <redacted values> using <redacted sql>
#2

Error Code 5 indicates a SQLITE_BUSY error.

https://www.sqlite.org/rescode.html#busy

Are you using multiple threads that are concurrently reading and writing to the database?

If so, you might try enabling WAL mode to see if that helps.

PRAGMA journal_mode=WAL;

https://www.sqlite.org/wal.html


#3

Yes, i am using multiple threads.

PRAGMA journal_mode=WAL;

Didn’t help !

java.util.concurrent.TimeoutException: net.sqlcipher.database.SQLiteCompiledSql.finalize() timed out after 10 seconds
at java.lang.Object.wait(Native Method)
at java.lang.Thread.parkFor(Thread.java:1205)
at sun.misc.Unsafe.park(Unsafe.java:325)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:846)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1175)
at java.util.concurrent.locks.ReentrantLock$FairSync.lock(ReentrantLock.java:195)
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:256)
at net.sqlcipher.database.SQLiteDatabase.lock(SQLiteDatabase.java:520)
at net.sqlcipher.database.SQLiteCompiledSql.releaseSqlStatement(SQLiteCompiledSql.java:106)
at net.sqlcipher.database.SQLiteCompiledSql.finalize(SQLiteCompiledSql.java:152)


#4

@srinivas3120 you should then try to set a busy timeout, to allow time for locks to clear, and ensure that your application is not continuously writing to the database.

https://www.sqlite.org/pragma.html#pragma_busy_timeout


#5

How do i choose value of time out ? what are the consequences of it ?

by default it got timed out after 10secs. 10 secs is lot !!

java.util.concurrent.TimeoutException: net.sqlcipher.database.SQLiteCompiledSql.finalize() timed out after 10 seconds