runtime: AccessViolationException using System.Data.OleDb
Hi all,
we get a AccessViolationException when using System.Data.OleDb with “Microsoft OLE DB Provider for Visual FoxPro 9.0” (vfpoledb) after inserting a new row with a DataTable and OleDbDataAdapter.Update().
ExceptionDetails:
StackTrace: null
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467261
HelpLink: null
InnerException: null
Message: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source: null
TargetSite: null
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.ExecuteNonQuery()
at System.Data.Common.DbDataAdapter.UpdateRowExecute(System.Data.Common.RowUpdatedEventArgs, System.Data.IDbCommand, System.Data.StatementType)
at System.Data.Common.DbDataAdapter.Update(System.Data.DataRow[], System.Data.Common.DataTableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(System.Data.DataTable, System.Data.Common.DataTableMapping)
at System.Data.Common.DbDataAdapter.Update(System.Data.DataTable)
at OleDBTest.Program.Main(System.String[])
associated Code:
using (OleDbConnection oledbConn = new OleDbConnection(@"Provider=vfpoledb;Data Source=d:\temp\dbfile.dbf;Collating Sequence = machine;")) {
oledbConn.Open();
using (OleDbDataAdapter da = new OleDbDataAdapter($"select * from dbfile.dbf", oledbConn)) {
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.InsertCommand = cb.GetInsertCommand();
DataTable dt = new DataTable();
da.Fill(dt);
var customerRow = dt.NewRow();
//Fill columns
dt.Rows.Add(customerRow);
da.Update(dt); // <-- the AccessViolationException is thrown here
}
}
We ported the code from classic .Net Framework (4.8) where the code works without a problem.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 55 (25 by maintainers)
Commits related to this issue
- Fixing AccessViolationException on x86 architecture Fixes: #981 — committed to maryamariyan/runtime by maryamariyan 4 years ago
People who are working on EntityFrameworkCore.Jet (https://github.com/bubibubi/EntityFrameworkCore.Jet/issues/34) will probably need these implementations in 3.1 as well, as they should encounter the same errors. @FreddyD-GH @lauxjpn @bubibubi
We’ll consider it for servicing once we have a fix ready. We’ll first check the fix into master, you’d be able to pull down a nightly package build of this (since it’s a standalone nuget), and we’ll follow up with servicing request after that.
Yes, got the repro for AccessViolationException on x86 architecture and confirmed what causes the exception and how to fix it.
@jader1313 The error you are getting while running the tests is probably because you didn’t follow all of the steps in order to run them. What we do is that we will build a special SDK during our regular build in the repo, and then we will use that one to run our tests, but looks like you didn’t do that and only installed a 5.0 sdk which is not enough. In order to be able to run our tests please run the following commands from a command prompt:
That should get the tests from that test project to run. If you want to add test cases and re run the tests, you only have to run that last command, no need to re run the first two which will take longer.