1

我正在构建一个.NET Core 3控制台应用程序,EF Core 2.2.xEntityFrameworkCore.Jet执行一些通用的读写访问数据库(mdb)。x86正如文档所说,我正在编译。目标是将丢失的大量数据从旧系统迁移到新系统(同步数据)。

我已经搭建了数据库,我可以完美地从数据库中读取,但是一旦我去更新一个实体,我就会遇到访问冲突异常:

代码示例(缩写为缩写):

public void SetSynced(int id)
{
    var item = _db.Products.Where(x => x.Id == id).Single();
    item.NeedsSyncing = false;
    _db.SaveChanges();
}

命中此代码时,会出现以下异常(无内部异常)

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

我不明白为什么会发生这种情况,因为我可以完美地读取数据库,它仅在写入时才会这样做。

我尝试使用以下连接字符串(驱动程序),但最终结果相同:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password;`
Provider=Microsoft.jet.oledb.4.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password;

x64阅读作品上运行时,但出现以下异常:

System.Data.OleDb.OleDbException (0x80004002): No error message available, result code: E_NOINTERFACE(0x80004002).

我在这里迷路了,在黑暗中寻找。有没有人有我在哪里看的经验/想法?

2020 年 2 月 2 日更新:我尝试使用 OleDb 手动连接并运行查询以查看它带给我的位置。下面的代码有效。当我用上面的代码切换它时,它再次失败。

db = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\database.mdb;Jet OLEDB:Database Password = password");
db.Open();
var command = new OleDbCommand($"UPDATE Products SET NeedsSyncing = 0 WHERE Id= 1", db);
var res = command.ExecuteNonQuery();

设置后,JetConfiguration.ShowSqlStatements = true我得到了以下堆栈跟踪:

ExecuteDbDataReader==========
UPDATE [Products] SET [PictureName] = @p0
WHERE [Id] = @p1;
SELECT @@ROWCOUNT;


@p1(Int32) = 1
@p0(String) = 'notfound.jpg'
Fatal error. 0xC0000005
   at System.Data.Common.UnsafeNativeMethods+ICommandWithParameters.SetParameterInfo(IntPtr, IntPtr[], System.Data.OleDb.tagDBPARAMBINDINFO[])
   at System.Data.OleDb.OleDbCommand.ApplyParameterBindings(ICommandWithParameters, System.Data.OleDb.tagDBPARAMBINDINFO[])
   at System.Data.OleDb.OleDbCommand.CreateAccessor()
   at System.Data.OleDb.OleDbCommand.InitializeCommand(System.Data.CommandBehavior, Boolean)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(System.Data.CommandBehavior, System.Object ByRef)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(System.Data.CommandBehavior, System.String)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(System.Data.CommandBehavior)
   at System.Data.OleDb.OleDbCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
   at System.Data.Common.DbCommand.ExecuteReader(System.Data.CommandBehavior)
   at System.Data.Jet.JetCommand.InternalExecuteDbDataReader(System.String, System.Data.CommandBehavior)
   at System.Data.Jet.JetCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Diagnostics.DbCommandMethod, System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Microsoft.EntityFrameworkCore.DbContext, System.ValueTuple`2<System.Collections.Generic.IEnumerable`1<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch>,Microsoft.EntityFrameworkCore.Storage.IRelationalConnection>)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[[System.ValueTuple`2[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.ValueTuple`2<System.__Canon,System.__Canon>, System.Func`3<Microsoft.EntityFrameworkCore.DbContext,System.ValueTuple`2<System.__Canon,System.__Canon>,Int32>, System.Func`3<Microsoft.EntityFrameworkCore.DbContext,System.ValueTuple`2<System.__Canon,System.__Canon>,Microsoft.EntityFrameworkCore.Storage.ExecutionResult`1<Int32>>)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(System.Collections.Generic.IEnumerable`1<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch>, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection)
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(System.Collections.Generic.IReadOnlyList`1<Microsoft.EntityFrameworkCore.Update.IUpdateEntry>)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(System.Collections.Generic.IReadOnlyList`1<Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry>)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
   at Cashmaster.BackgroundWorker.Services.CashMasterService.Crash()

Nuget 包 + 版本(与 Jet 相关):

Microsoft.EntityFrameworkCore 2.2.6
EntityFrameworkCore.Jet 2.2.0
System.Data.OleDb 4.7.0

运行这一切.NET Core 3.1

4

1 回答 1

0

通过将 x86 特定结构迁移到 AnyCPU for System.Data.OleDb #32509在 GitHub 上跟踪了该问题,并由社区成员通过修复 System.Data.OleDb #33899 中的 x86 打包问题进行了修复。

要解决项目中的问题,请使用最新版本的 EF Core 3.1.x(当前为3.1.10)和最新版本EntityFrameworkCore.Jet(当前为预发布 3.1.0-alpha.4)以及System.Data.OleDb版本5.0.0

于 2020-12-25T19:03:16.290 回答