Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'The database file is locked' with System.Data.SQLite

I am suddenly getting the following errors from SQLite after adding a new transaction:

The database file is locked database is locked

Has anyone seen this? I added an update transaction (following some successful selects/inserts). I can't find anything different about this one...

like image 521
AdamC Avatar asked Dec 03 '10 18:12

AdamC


People also ask

How do you fix SQLite database is locked?

If you want to remove a "database is locked" error then follow these steps: Copy your database file to some other location. Replace the database with the copied database. This will dereference all processes which were accessing your database file.

What causes a SQLite database to be locked?

Reasons Responsible for Error Database is Locked. This error code occurs when the user tries to perform two inappropriate operations on a database at the same detail and on the same database connection.

How do you check if SQLite database is locked?

There's no use checking before (if that is possible), it still can get locked between the check and your next call. Better would be to make your call, and handle possible exceptions, eg. retry a number of times and report an error after too much retries.


1 Answers

I figured it out. From looking at this [really old] thread on the phxsoftware site, it seems like there can be locking problems if you don't immediately dispose of readers and commands after executing them.

I fixed my problem by making sure to not keep commands or readers around and surrounding them with using statements.

(Web archived version of the link)

like image 152
AdamC Avatar answered Oct 06 '22 00:10

AdamC