Sqlite DB Locked on Azure Dotnet Core Entity Framework Sqlite DB Locked on Azure Dotnet Core Entity Framework docker docker

Sqlite DB Locked on Azure Dotnet Core Entity Framework


Can you share your update method? sometimes database is locked because C# code does not use database connection/transaction appropriately.

I suggest you have a look at your update method and see if database connection and transaction is used correctly. microsoft documentation might help

using (var context = new BloggingContext()){    using (var transaction = context.Database.BeginTransaction())    {        try        {            context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" });            context.SaveChanges();            context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/visualstudio" });            context.SaveChanges();            var blogs = context.Blogs                .OrderBy(b => b.Url)                .ToList();            // Commit transaction if all commands succeed, transaction will auto-rollback            // when disposed if either commands fails            transaction.Commit();        }        catch (Exception)        {            // TODO: Handle failure        }    }}


This is most often caused by open or pending connection requests that couldn't be processed because of some earlier process grabbing up the lock. You can try the following implementation, using which connection and commands can be disposed correctly in order.

private static void ExecuteNonQuery(string queryString){    using (var connection = new SQLiteConnection(               ConnectionString))    {        using (var command = new SQLiteCommand(queryString, connection))        {            command.Connection.Open();            command.ExecuteNonQuery();        }    }}