I got following exception when I tried to modify the SQLite database using Entity Framework
System.Data.Entity.Core.EntityException: System.Data.Entity.Core.EntityException: An error occurred while starting a transaction on the provider connection. See the inner exception for details. —> System.Data.SQLite.SQLiteException: database is locked
database is locked.
The code causing the problem is following (the orderDao and productDao is wrapper of Entity Framework to manipulate SQLite database)
orderDao.Add(new Order() { CreateTime = DateTime.Now, OrderId = DateTime.Now.ToString("yyyyMMddHHmmss"), ItemDetails = new List<ProductPurchase>() { new ProductPurchase() { Amount = 2, Product = productDao.Find(p => p.Title == "Milk").FirstOrDefault() } } });
One common situation to cause this problem is that another application is accessing the same database.
In my situation it’s because that I opened the database with DB Browser for SQLite, deleted a database table and not applying the changes.
Clicking Write Changes (or Revert Changes or Close Database) and the error will be gone.
The post .NET SQLite database is locked appeared first on Redino blog.