关闭并重新启动应用程序后,我偶尔会遇到以下错误:
SQLite错误4:'由于ROLLBACK而中止'。
特别是在调用以下查询时发生此异常。它是在循环内启动后的第一个查询,但不一定是导致异常的第一个调用。
public ObservableCollection<Device> GetConnectedDevicesNoTracking(ConnectionPoint connectionPoint)
{
var list = DatabaseContext.Devices
.AsNoTracking()
.Include(d => d.ConnectionPointDevices)
.ThenInclude(d => d.ConnectionPoint)
.Where(d => d.ConnectionPointDevices.Any(cpd => cpd.ConnectionPointId == connectionPoint.ConnectionPointId))
.Include(d => d.Supplier1)
.Include(d => d.CableType1)
.Include(d => d.Sockets)
.ToList();
return new ObservableCollection<Device>(list);
}
有关如何避免这种情况的提示吗?在上下文中调用SaveChanges()
时没有例外。
上下文保存方法:
public int Complete()
{
try
{
var count = _context.SaveChanges();
return count;
}
catch (DbUpdateConcurrencyException ex)
{
throw new Exception("Database Concurrency error while trying to save changes: ", ex);
}
catch (DbUpdateException ex)
{
throw new Exception("Database error while trying to save changes: ", ex);
}
catch (Exception ex)
{
throw new Exception("Database general error while trying to save changes: ", ex);
}
}
例外详情
Microsoft.Data.Sqlite.SqliteException未被用户代码
处理 ErrorCode = -2147467259 HResult = -2147467259 Message = SQLite Error 4: '由于ROLLBACK而中止'。来源= Microsoft.Data.Sqlite
SqliteErrorCode = 4 StackTrace: 在Microsoft.Data.Sqlite.Interop.MarshalEx.ThrowExceptionForRC(Int32 rc, Sqlite3Handle db) 在Microsoft.Data.Sqlite.SqliteDataReader.Read() 在Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext() 在Microsoft.EntityFrameworkCore.Query.QueryMethodProvider。&lt; _ShapedQuery&gt; d__31.MoveNext() at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30
1.MoveNext() 在Microsoft.EntityFrameworkCore.Query.QueryMethodProvider。&lt; _Include&gt; d__301.MoveNext() at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30
1.MoveNext() 在Microsoft.EntityFrameworkCore.Query.QueryMethodProvider。&lt; _Include&gt; d__301.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor
1.EnumeratorExceptionInterceptor.MoveNext() 在System.Collections.Generic.List1..ctor(IEnumerable
1个集合) 在System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source) at FxPlugin.Persistence.Repositories.ConnectionPointRepository.GetConnectedDevicesNoTracking(ConnectionPoint connection:)在C:\ Users \ user \ Documents \ Visual Studio中 2015年\项目\ FxEditorDatabaseStructure \ FxEditorDatabaseStructure \持久性\库\ ConnectionPointRepository.cs:行 168 at FxPlugin.ViewModels.ProjectDeviceDatabaseViewModel.InitialLoading_DoWork(Object 发件人,DoWorkEventArgs e)在C:\ Users \ user \ Documents \ Visual中 工作室 2015年\项目\ FxEditorDatabaseStructure \ FxEditorDatabaseStructure \的ViewModels \ ProjectDeviceDatabaseViewModel.cs:行 488 在System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) 在System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object 参数)InnerException: