SQLite database locked by ASP.Net

Posted by Blake on 9/6/2014
)

One of the downsides of using SQLite as a database on a website are potential locking issues that can occur. If you don't cleanup your connections properly you could run into issues where the database will stay locked until the site recycles (which could cause errors reading/writing to the database or trying to deploy a new copy). You may see an error something like this:

    An error was encountered when processing operation 'Read File' on 'Test.db'

If the database gets stuck in a lock state the temporary solution to unlock it will be to reset your site. If you don't have access to IIS (or your Azure console) you can make a slight change to the web.config to force the recycle that will release the lock. You can also publish an app_offline.htm file and then delete it to force a reset (this is probably the better way to do it). In the end you will want to figure out why the lock is being held and if you can prevent it (I would start by making sure that you have closed and disposed of all of your database objects).