Database locked issue
Posted: Wed 03 Jun 2020 06:53
Hi,
I am working on a multithreaded application that uses dotconnect to connect to an sqlite database.
Once in a couple of months I get the following error:
InnerException:
Type: System.Data.Entity.Core.UpdateException
Message: An error occurred while updating the entries. See the inner exception for details.
StackTrace: at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
InnerException:
Type: Devart.Data.SQLite.SQLiteException
Message: The database file is locked
database is locked
StackTrace: at Devart.Data.SQLite.a8.d(bv A_0)
at Devart.Data.SQLite.bv.b()
at Devart.Data.SQLite.af.e()
at Devart.Data.SQLite.SQLiteDataReader.c()
at Devart.Data.SQLite.SQLiteCommand.InternalExecute(CommandBehavior behavior, IDisposable statement, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
I am using a simple unit of work and repository pattern around the application. Example:
using (var unitOfWork = new UnitOfWork(new ApplicationDbContext()))
{
var testRepo = unitOfWork.Get<ITestRepository>();
//do repo and entity operations
unitOfWork.DbContext.SaveChanges();
}
At the moment I encounter a database error I log the following:
- all started unit of works .All of them seem to have the database connection closed (unitOfWork.DbContext.Database.Connection = Closed).
- all the processes that are locking the database file (only my application is using it).
I also log all the data written in the database and at the time of the error nothing seems to have been saved in parallel.
I am using dotconnect professional version 5.10.1061.
Connection string used:
new SQLiteConnectionStringBuilder
{
BinaryGUID = false,
DataSource = fullDatabasePath,
FailIfMissing = false,
DateTimeFormat = SQLiteDateFormats.ISO8601,
JournalMode = JournalMode.WAL,
Pooling = true
};
Any ideas on what could keep the database file locked?
Thank you,
Paul
I am working on a multithreaded application that uses dotconnect to connect to an sqlite database.
Once in a couple of months I get the following error:
InnerException:
Type: System.Data.Entity.Core.UpdateException
Message: An error occurred while updating the entries. See the inner exception for details.
StackTrace: at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
InnerException:
Type: Devart.Data.SQLite.SQLiteException
Message: The database file is locked
database is locked
StackTrace: at Devart.Data.SQLite.a8.d(bv A_0)
at Devart.Data.SQLite.bv.b()
at Devart.Data.SQLite.af.e()
at Devart.Data.SQLite.SQLiteDataReader.c()
at Devart.Data.SQLite.SQLiteCommand.InternalExecute(CommandBehavior behavior, IDisposable statement, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
I am using a simple unit of work and repository pattern around the application. Example:
using (var unitOfWork = new UnitOfWork(new ApplicationDbContext()))
{
var testRepo = unitOfWork.Get<ITestRepository>();
//do repo and entity operations
unitOfWork.DbContext.SaveChanges();
}
At the moment I encounter a database error I log the following:
- all started unit of works .All of them seem to have the database connection closed (unitOfWork.DbContext.Database.Connection = Closed).
- all the processes that are locking the database file (only my application is using it).
I also log all the data written in the database and at the time of the error nothing seems to have been saved in parallel.
I am using dotconnect professional version 5.10.1061.
Connection string used:
new SQLiteConnectionStringBuilder
{
BinaryGUID = false,
DataSource = fullDatabasePath,
FailIfMissing = false,
DateTimeFormat = SQLiteDateFormats.ISO8601,
JournalMode = JournalMode.WAL,
Pooling = true
};
Any ideas on what could keep the database file locked?
Thank you,
Paul