"Database is locked" with SQLite and C# "Database is locked" with SQLite and C# sqlite sqlite

"Database is locked" with SQLite and C#


Ok everyone, thanks for your help.I just have to .dispose() two readers in an other function before insert/update, and it works !


You're trying to run a second command before you've disposed the first. cmdExist will likely have the database locked when you try to run cmdUdpdate.

You should refactor your code so that the using blocks for your commands aren't nested.

Does SQLite lock the database file on reads? seems to suggest you'd be able to read then write, so I'd also make sure you don't have the database open from elsewhere. It does still seem to be the likely culprit though.


Try simplifying your select then update into a single statement like this:

UPDATE ... WHERE id = (SELECT id FROM ... )

If this succeeds, then you know that the failure was due to the interaction between the select and the update -- i.e. the separate select must have held a shared lock open on the database that the update ran into.

If this combined statement fails due to a locked database, then you know that something else is blocking the update -- not the select. There is something else in the application causing the database lock failure.