runtime icon indicating copy to clipboard operation
runtime copied to clipboard

AccessViolationException using System.Data.OleDb

Open danielSt-dev opened this issue 6 years ago • 55 comments

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.

danielSt-dev avatar Dec 17 '19 15:12 danielSt-dev

I wonder whether you could get more callstack out of a native debugger? Probably this is all there is, but worth a try?

danmoseley avatar Dec 17 '19 17:12 danmoseley

cc: @ajcvickers @cheenamalhotra @david-engel

maryamariyan avatar Dec 17 '19 21:12 maryamariyan

@danmosemsft So, I have tried to get the exception details out of windbg (the new windbg preview from microsoft store ;-)

Here is the output from windbg command window:

exception occured:

(fec.880): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=000006e9 ebx=08f14f9e ecx=00000001 edx=0277e89c esi=0867653c edi=0277e8b4
eip=0c0b40b4 esp=0277e870 ebp=0277e8d8 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010202
vfpoledb!DllGetClassObject+0xb92b:
0c0b40b4 668b08          mov     cx,word ptr [eax]        ds:002b:000006e9=????


0:000> k
 # ChildEBP RetAddr  
WARNING: Stack unwind information not available. Following frames may be wrong.
00 0277e8d8 0866752b vfpoledb!DllGetClassObject+0xb92b
01 0277e980 08667414 0x866752b
02 0277e9a8 08666332 0x8667414
03 0277e9dc 07e19613 0x8666332
04 0277e9fc 07e190e9 0x7e19613
05 0277ea10 07e189e8 0x7e190e9
06 0277ea90 08666217 0x7e189e8
07 0277eaa0 305e953b 0x8666217
08 0277eaf4 305e8c0e System_Data_Common!System.Data.Common.DbDataAdapter.UpdateRowExecute(System.Data.Common.RowUpdatedEventArgs, System.Data.IDbCommand, System.Data.StatementType)$##60016CD+0x3f
09 0277eb84 305e94f1 System_Data_Common!System.Data.Common.DbDataAdapter.Update(System.Data.DataRow[], System.Data.Common.DataTableMapping)$##60016C9+0x742
0a 0277eb98 305e824e System_Data_Common!System.Data.Common.DbDataAdapter.UpdateFromDataTable(System.Data.DataTable, System.Data.Common.DataTableMapping)$##60016CC+0x2d
0b 0277ebe4 06fb254f System_Data_Common!System.Data.Common.DbDataAdapter.Update(System.Data.DataTable)$##60016C7+0x18a
0c 0277ec48 0fb29a2f 0x6fb254f
0d 0277ec54 0fac9254 coreclr!CallDescrWorkerInternal+0x34 [F:\workspace\_work\1\s\src\vm\i386\asmhelpers.asm @ 615] 
0e (Inline) -------- coreclr!CallDescrWorkerWithHandler+0x55 [f:\workspace\_work\1\s\src\vm\callhelpers.cpp @ 70] 
0f 0277ecec 0fb1b189 coreclr!MethodDescCallSite::CallTargetWorker+0x167 [f:\workspace\_work\1\s\src\vm\callhelpers.cpp @ 604] 
10 (Inline) -------- coreclr!MethodDescCallSite::Call+0x11 [f:\workspace\_work\1\s\src\vm\callhelpers.h @ 468] 
11 0277ee60 0fa8ca12 coreclr!RunMain+0x1e3 [f:\workspace\_work\1\s\src\vm\assembly.cpp @ 1558] 
12 0277f0c4 0fa8c614 coreclr!Assembly::ExecuteMainMethod+0x178 [f:\workspace\_work\1\s\src\vm\assembly.cpp @ 1681] 
13 0277f1b0 0fa8c433 coreclr!CorHost2::ExecuteAssembly+0x184 [f:\workspace\_work\1\s\src\vm\corhost.cpp @ 460] 
14 0277f204 568b46e6 coreclr!coreclr_execute_assembly+0xd3 [f:\workspace\_work\1\s\src\dlls\mscoree\unixinterface.cpp @ 412] 
15 0277f228 568c2e1d hostpolicy!coreclr_t::execute_assembly+0x26 [f:\workspace\_work\1\s\src\corehost\cli\hostpolicy\coreclr.cpp @ 145] 
16 0277f2d8 568c2a87 hostpolicy!run_app_for_context+0x33d [f:\workspace\_work\1\s\src\corehost\cli\hostpolicy\hostpolicy.cpp @ 247] 
17 0277f310 568c3bd1 hostpolicy!run_app+0x57 [f:\workspace\_work\1\s\src\corehost\cli\hostpolicy\hostpolicy.cpp @ 276] 
18 0277f418 5694d129 hostpolicy!corehost_main+0xf1 [f:\workspace\_work\1\s\src\corehost\cli\hostpolicy\hostpolicy.cpp @ 390] 
19 0277f48c 5694fa56 hostfxr!execute_app+0x309 [f:\workspace\_work\1\s\src\corehost\cli\fxr\fx_muxer.cpp @ 147] 
1a 0277f514 5694eafe hostfxr!`anonymous namespace'::read_config_and_execute+0xa6 [f:\workspace\_work\1\s\src\corehost\cli\fxr\fx_muxer.cpp @ 502] 
1b 0277f578 5694cd65 hostfxr!fx_muxer_t::handle_exec_host_command+0xee [f:\workspace\_work\1\s\src\corehost\cli\fxr\fx_muxer.cpp @ 952] 
1c 0277f68c 569493d6 hostfxr!fx_muxer_t::execute+0x225 [f:\workspace\_work\1\s\src\corehost\cli\fxr\fx_muxer.cpp @ 541] 
1d 0277f720 0015f3a3 hostfxr!hostfxr_main_startupinfo+0x76 [f:\workspace\_work\1\s\src\corehost\cli\fxr\hostfxr.cpp @ 33] 
1e 0277f874 0015f59e apphost!exe_start+0x7e3 [f:\workspace\_work\1\s\src\corehost\corehost.cpp @ 220] 
1f 0277f890 00160dec apphost!wmain+0x6e [f:\workspace\_work\1\s\src\corehost\corehost.cpp @ 279] 
20 (Inline) -------- apphost!invoke_main+0x1c [d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 90] 
21 0277f8d8 75440419 apphost!__scrt_common_main_seh+0xfa [d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
22 0277f8e8 7714662d KERNEL32!BaseThreadInitThunk+0x19
23 0277f944 771465fd ntdll!__RtlUserThreadStart+0x2f
24 0277f954 00000000 ntdll!_RtlUserThreadStart+0x1b


0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

Failed to request MethodData, not in JIT code range
MethodDesc:   086d9478
Method Name:          ILStubClass.IL_STUB_CLRtoCOM(IntPtr, IntPtr[], System.Data.OleDb.tagDBPARAMBINDINFO[])
Class:                07078b98
MethodTable:          07078bec
mdToken:              06000000
Module:               07077834
IsJitted:             yes
Current CodeAddr:     08667440
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           08667440  (Optimized)
     NativeCodeVersion:  00000000
MethodDesc:   06fcb364
Method Name:          System.Data.OleDb.OleDbCommand.ApplyParameterBindings(ICommandWithParameters, System.Data.OleDb.tagDBPARAMBINDINFO[])
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              060002F4
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     086673c8
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           086673c8  (Optimized)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 423
MethodDesc:   06fcb354
Method Name:          System.Data.OleDb.OleDbCommand.CreateAccessor()
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              060002F3
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     08666238
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           08666238  (Optimized)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 401
MethodDesc:   06fcb578
Method Name:          System.Data.OleDb.OleDbCommand.InitializeCommand(System.Data.CommandBehavior, Boolean)
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              06000315
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     07e19558
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           07e19558  (QuickJitted)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 1141
MethodDesc:   06fcb480
Method Name:          System.Data.OleDb.OleDbCommand.ExecuteCommand(System.Data.CommandBehavior, System.Object ByRef)
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              06000306
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     07e190d0
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           07e190d0  (QuickJitted)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 764
MethodDesc:   06fcb470
Method Name:          System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(System.Data.CommandBehavior, System.String)
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              06000305
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     07e18968
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           07e18968  (QuickJitted)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 622
MethodDesc:   06fcb4f0
Method Name:          System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
Class:                06ff68d0
MethodTable:          06fcb7b0
mdToken:              0600030D
Module:               070a922c
IsJitted:             yes
Current CodeAddr:     086661f8
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           086661f8  (QuickJitted)
     NativeCodeVersion:  00000000
Source file:  /_/src/System.Data.OleDb/src/OleDbCommand.cs @ 917
MethodDesc:   06dbf358
Method Name:          OleDbTest.Program.Main(System.String[])
Class:                06ec555c
MethodTable:          06dbf374
mdToken:              06000001
Module:               06dbdfa0
IsJitted:             yes
Current CodeAddr:     06fb2428
Version History:
  ILCodeVersion:      00000000
  ReJIT ID:           0
  IL Addr:            00000000
     CodeAddr:           06fb2428  (MinOptJitted)
     NativeCodeVersion:  00000000
Source file:  D:\Testanwendungen\OleDbTest\Program.cs @ 22

KEY_VALUES_STRING: 1
    Key  : AV.Fault
    Value: Read

    Key  : Analysis.CPU.Sec
    Value: 2

    Key  : Analysis.DebugAnalysisProvider.CPP
    Value: Create: 8007007e on DESLNPC220

    Key  : Analysis.DebugData
    Value: CreateObject

    Key  : Analysis.DebugModel
    Value: CreateObject

    Key  : Analysis.Elapsed.Sec
    Value: 4

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 164

    Key  : Analysis.System
    Value: CreateObject

    Key  : CLR.Engine
    Value: CORECLR

    Key  : CLR.Version
    Value: 4.700.19.56402

    Key  : Timeline.OS.Boot.DeltaSec
    Value: 8134

    Key  : Timeline.Process.Start.DeltaSec
    Value: 1138

ADDITIONAL_XML: 1
NTGLOBALFLAG:  70
PROCESS_BAM_CURRENT_THROTTLED: 0
PROCESS_BAM_PREVIOUS_THROTTLED: 0
APPLICATION_VERIFIER_FLAGS:  0

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 0c0b40b4 (vfpoledb!DllGetClassObject+0x0000b92b)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 000006e9
Attempt to read from address 000006e9

FAULTING_THREAD:  00000880
PROCESS_NAME:  apphost.exe
READ_ADDRESS:  000006e9 
ERROR_CODE: (NTSTATUS) 0xc0000005 - Die Anweisung in 0x%p verwies auf Arbeitsspeicher bei 0x%p. Der Vorgang %s konnte im Arbeitsspeicher nicht durchgef hrt werden.
EXCEPTION_CODE_STR:  c0000005
EXCEPTION_PARAMETER1:  00000000
EXCEPTION_PARAMETER2:  000006e9

IP_ON_HEAP:  0866752b
The fault address in not in any loaded module, please check your build's rebase
log at <releasedir>\bin\build_logs\timebuild\ntrebase.log for module which may
contain the address if it were loaded.

FRAME_ONE_INVALID: 1

STACK_TEXT:  
WARNING: Stack unwind information not available. Following frames may be wrong.
0277e8d8 0866752b 086764c4 0000002c 04986f5c vfpoledb!DllGetClassObject+0xb92b
0277e980 08667414 04985bec 04986f54 0498458c 0x866752b
0277e9a8 08666332 04985bec 0493eb6c 0498485c 0x8667414
0277e9dc 07e19613 00000000 00000000 00000000 0x8666332
0277e9fc 07e190e9 00000000 00000000 0493e270 0x7e19613
0277ea10 07e189e8 0277ea58 00000000 00000000 0x7e190e9
0277ea90 08666217 04984560 0493e270 0277eaf4 0x7e189e8
0277eaa0 305e953b 00000000 00000008 00638927 0x8666217
0277eaf4 305e8c0e 00000001 0493e270 00000000 System_Data_Common!System.Data.Common.DbDataAdapter.UpdateRowExecute(System.Data.Common.RowUpdatedEventArgs, System.Data.IDbCommand, System.Data.StatementType)$##60016CD+0x3f
0277eb84 305e94f1 049812b0 04921fbc 04942360 System_Data_Common!System.Data.Common.DbDataAdapter.Update(System.Data.DataRow[], System.Data.Common.DataTableMapping)$##60016C9+0x742
0277eb98 305e824e 049812b0 049111c8 00000000 System_Data_Common!System.Data.Common.DbDataAdapter.UpdateFromDataTable(System.Data.DataTable, System.Data.Common.DataTableMapping)$##60016CC+0x2d
0277ebe4 06fb254f 00000000 049425d8 049811e8 System_Data_Common!System.Data.Common.DbDataAdapter.Update(System.Data.DataTable)$##60016C7+0x18a
0277ec48 0fb29a2f 00000008 0277ecec 0fac9254 0x6fb254f
0277ec54 0fac9254 0277ecc0 0277ee50 0faa5d80 coreclr!CallDescrWorkerInternal+0x34
0277ecec 0fb1b189 0277ee28 00000000 00000000 coreclr!MethodDescCallSite::CallTargetWorker+0x167
0277ee60 0fa8ca12 0277ee94 0277f198 aa5da6d9 coreclr!RunMain+0x1e3
0277f0c4 0fa8c614 0277f198 80004005 aa5da7ad coreclr!Assembly::ExecuteMainMethod+0x178
0277f1b0 0fa8c433 0281203c 00000001 02844f58 coreclr!CorHost2::ExecuteAssembly+0x184
0277f204 568b46e6 0281203c 00000001 00000000 coreclr!coreclr_execute_assembly+0xd3
0277f228 568c2e1d 00000000 00000000 02844ad8 hostpolicy!coreclr_t::execute_assembly+0x26
0277f2d8 568c2a87 02811b90 00000000 027fe354 hostpolicy!run_app_for_context+0x33d
0277f310 568c3bd1 00000000 027fe354 568c3ae0 hostpolicy!run_app+0x57
0277f418 5694d129 00000001 027fe350 e42af621 hostpolicy!corehost_main+0xf1
0277f48c 5694fa56 0277f4ec 0280fb98 00000001 hostfxr!execute_app+0x309
0277f514 5694eafe 0277f694 0277f6d4 0277f664 hostfxr!`anonymous namespace'::read_config_and_execute+0xa6
0277f578 5694cd65 0277f694 0277f6d4 0277f664 hostfxr!fx_muxer_t::handle_exec_host_command+0xee
0277f68c 569493d6 02800000 0280d7a0 0280d888 hostfxr!fx_muxer_t::execute+0x225
0277f720 0015f3a3 00000001 027fe350 0280d888 hostfxr!hostfxr_main_startupinfo+0x76
0277f874 0015f59e 00000001 027fe350 027fe350 apphost!exe_start+0x7e3
0277f890 00160dec 00000001 027fe350 027fce28 apphost!wmain+0x6e
0277f8d8 75440419 02598000 75440400 0277f944 apphost!__scrt_common_main_seh+0xfa
0277f8e8 7714662d 02598000 38d39b8b 0

0000000 KERNEL32!BaseThreadInitThunk+0x19
0277f944 771465fd ffffffff 771651df 00000000 ntdll!__RtlUserThreadStart+0x2f
0277f954 00000000 00160e80 02598000 00000000 ntdll!_RtlUserThreadStart+0x1b

STACK_COMMAND:  ~0s ; .cxr ; kb
SYMBOL_NAME:  vfpoledb!DllGetClassObject+b92b
MODULE_NAME: vfpoledb
IMAGE_NAME:  vfpoledb.dll
FAILURE_BUCKET_ID:  NULL_CLASS_PTR_READ_c0000005_vfpoledb.dll!DllGetClassObject
BUCKET_ID_MODPRIVATE: 1
OS_VERSION:  10.0.17763.1
BUILDLAB_STR:  rs5_release
OSPLATFORM_TYPE:  x86
OSNAME:  Windows 10
FAILURE_ID_HASH:  {98f4425d-e56d-c1e8-ee21-0703cc81a526}
Followup:     MachineOwner
---------

.net core 3.1 sample project including foxpro-Database attached: OleDbTest.zip

Visua FoxPro oledb driver downloaded from: https://www.microsoft.com/en-us/download/details.aspx?id=14839

Please let me know if you need further infos.

danielSt-dev avatar Dec 18 '19 10:12 danielSt-dev

From the source code it seems you're tryjng to update "da" object after using block is closed? Could you place it inside using block and try again plz?

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);
    }
}

cheenamalhotra avatar Dec 19 '19 15:12 cheenamalhotra

From the source code it seems you're tryjng to update "da" object after using block is closed? Could you place it inside using block and try again plz?

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);
    }
}

@cheenamalhotra: aah, sorry. my mistake while formatting the code in github. The da.Update(dt) of course is within the using block and can't be outside because of compiler error.

initial comment was updated and thanks for the hint.

danielSt-dev avatar Dec 19 '19 15:12 danielSt-dev

I tested using a LocalDB database and OLE DB Driver for SQL Server and got a error too.

"Provider=MSOLEDBSQL;Server=(localdb)\MSSQLLocalDB;Database=SarathlalDb;DataTypeCompatibility=80;Integrated Security=SSPI; "

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

jader1313 avatar Dec 19 '19 17:12 jader1313

On testing same application with .NET Framework (tested 4.0-4.8), I see below exception:

System.Data.OleDb.OleDbException: 'Field DQSCHEMA does not accept null values.'

Which is expected exception and gets errors back from Native DLL. Whereas in .NET Core, the HRResult itself is not retrieved and Native DLL fails with reported exception from vfpoledb.dll

Exception thrown at 0x0C0B40B4 (vfpoledb.dll) in OleDbTest.exe: 0xC0000005: Access violation reading location 0x000007E1.

On comparing OleDbCommand.cs for .NET Core and .NET Framework reference, I see 1 difference which I'm not sure how relevant it is:

In .NET Core: https://github.com/dotnet/runtime/blob/4f9ae42d861fcb4be2fcd5d3d55d5f227d30e723/src/libraries/System.Data.OleDb/src/OleDbCommand.cs#L583-L587

In .NET Framework reference (link):

        new public OleDbDataReader ExecuteReader(CommandBehavior behavior) {
            OleDbConnection.ExecutePermission.Demand();
 
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<oledb.OleDbCommand.ExecuteReader|API> %d#, behavior=%d{ds.CommandBehavior}\n", ObjectID, (int)behavior);
            try {
                _executeQuery = true;
                return ExecuteReaderInternal(behavior, ADP.ExecuteReader);
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }

OleDbConnection.ExecutePermission.Demand(); is what seemed missing in .NET Core for all Execute APIs not just one.

@stephentoub @roji would that be related to user's issue? Could someone give it a try?

cheenamalhotra avatar Dec 19 '19 20:12 cheenamalhotra

I believe the problem is related to this https://github.com/dotnet/corefx/issues/42596

jader1313 avatar Dec 19 '19 20:12 jader1313

@jader1313

Could you also provide a repro with provider MSOLEDBSQL with LocalDB where you experience this?

cheenamalhotra avatar Dec 19 '19 20:12 cheenamalhotra

In .Net Core 3.0 or 3.1 with 1 parameter works, but with 2 or more parameters error occurs. Following example:

    string StrConn = "Provider=MSOLEDBSQL;Server=(localdb)\\MSSQLLocalDB;Database=SarathlalDb;DataTypeCompatibility=80;Integrated Security=SSPI; ";
    using (OleDbConnection connection = new OleDbConnection(StrConn))
    {
        connection.Open();
        using (OleDbCommand command = new OleDbCommand())
        {
            command.Connection = connection;
            command.CommandText =
                "INSERT INTO Employees(Id, Name) VALUES(?,?)";

            var par = new OleDbParameter();
            par.OleDbType = OleDbType.VarChar;
            par.Size = 250;
            par.Value = Guid.NewGuid().ToString();
            command.Parameters.Add(par);

            par = new OleDbParameter();
            par.OleDbType = OleDbType.VarChar;
            par.Size = 250;
            par.Value = "Test";
            command.Parameters.Add(par);
            command.Prepare();
            try
            {
                command.ExecuteNonQuery();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("ERRO: Could not perform INSERT INTO.", "SQL", command.CommandText);
                throw e;
            }
        }
    }

jader1313 avatar Dec 19 '19 20:12 jader1313

@cheenamalhotra

On testing same application with .NET Framework (tested 4.0-4.8), I see below exception:

System.Data.OleDb.OleDbException: 'Field DQSCHEMA does not accept null values.'

In the testapp I haven't considered the database scheme because I thought it is unnecessary. In our production app the row is correctly filled of course. Attached is the modified testapp with a correctly filled row. So in .NET Framework 4.8 no exception is thrown and the row is inserted correctly. In .NET Core 3.1 the AccessViolationException is still there.

I hope this helps for debugging and research. OleDbTest.zip

danielSt-dev avatar Dec 20 '19 09:12 danielSt-dev

I believe I am seeing this as well. I'm porting this (working...well it was under .NET Framework) to .NetCore.

I'm connecting to a very old AccessDB via OLE40 (this application is "glue" between that file and an SQL Server Database I use EF to talk to). Inside of a timed event I call some stored queries in the .mdb file, and that works just fine. Later on however, I get the same exception being reported here on the call to ExecuteReader(). This is my first mucking with .netcore, so bear with me.

EDIT/ADD: Later or earlier makes no difference. Any call to this query fails., even if I use a pooled connection.

            List<Player>
                people = bm.Players.Where(p => p.Name == "").ToList();

            OleDbCommand cmd2 = new OleDbCommand(
                    "Select * from [PlayerNumbers] where [Section] = ? AND [Table] = ? AND [Direction] = ?",
                    window._conn);

            foreach (var person in people)
            {
                cmd2.Parameters.Clear();

                cmd2.Parameters.AddWithValue("[Section]", person.SectionId);
                cmd2.Parameters.AddWithValue("[Table]", person.TableNumber);
                cmd2.Parameters.AddWithValue("[Direction]", person.Direction);

                OleDbDataReader reader2 = cmd2.ExecuteReader(); // EXCEPTION THROWN


JoeHz avatar Jan 04 '20 13:01 JoeHz

@ajcvickers @cheenamalhotra @ David-Engel @cheenamalhotra @ danielSt-dev @JoeHz:

Is there any way we can prioritize the solution of this problem, I think it's a major problem as it apparently affects System.Data.OleDb with any database.

jader1313 avatar Jan 17 '20 18:01 jader1313

@David-Engel

jader1313 avatar Jan 17 '20 18:01 jader1313

@maryamariyan @divega @cheenamalhotra @danmosemsft @saurabh500 @msftgits We are converting an EF6 provider to EF Core, but we are not getting ahead due to this problem with OleDbCommand with more than one parameter. We are stopped for almost 60 days, can someone help in solving this bug or at least give some forwarding?

jader1313 avatar Feb 04 '20 23:02 jader1313

@jader1313 do you mind adding your test case in a PR to OLEDB here and confirming the difference in behavior by running your test case in the two different frameworks (.net core and .net framework)?

Here is a doc page showing how to build and run tests on the runtime repo and to run in different frameworks: https://github.com/dotnet/runtime/tree/master/docs/workflow/building/libraries

maryamariyan avatar Feb 05 '20 01:02 maryamariyan

@maryamariyan I tried to run the tests but I am getting the following error:

[05/02/2020 9:59:42.882 ] ---------- Discovery started ---------- Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.

  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited) em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) [05/02/2020 9:59:42.951 ] ========== Discovery aborted: 0 tests found (0:00:00,0647166) ========== [05/02/2020 9:59:42.981 ] ---------- Run started ---------- O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.
  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.
  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. [05/02/2020 9:59:43.148 ] ========== Run aborted: 0 tests run (0:00:00,0720318) ==========

But i have:

C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet SDK do .NET Core (refletindo qualquer global.json): Version: 5.0.100-alpha.1.20073.4 Commit: bafdca8cc2

Ambiente de runtime: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet\sdk\5.0.100-alpha.1.20073.4\

Host (useful for support): Version: 5.0.0-alpha.1.20070.4 Commit: 46d7becc6c

.NET Core SDKs installed: 5.0.100-alpha.1.20073.4 [C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 5.0.0-alpha.1.20071.6 [C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.0-alpha.1.20070.4 [C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.0-alpha.1.20073.3 [C:\Projetos\DotNet\Desenvolvimento\DotNetCore\runtime.dotnet\shared\Microsoft.WindowsDesktop.App]

jader1313 avatar Feb 05 '20 13:02 jader1313

@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:

<runtimeRepoRoot>\coreclr.cmd -configuration Release
<runtimeRepoRoot>\libraries.cmd /p:CoreClrConfiguration=Release
<runtimeRepoRoot>\.dotnet\dotnet.exe msbuild src\libraries\System.Data.OleDb\tests\System.Data.OleDb.Tests.csproj /t:RebuildAndTest

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.

joperezr avatar Feb 05 '20 17:02 joperezr

@jader1313 I just realized our official builds on dotnet/runtime don't build for netfx any longer. However you can still follow @joperezr instructions to run any dotnet/runtime test for .net core.

In order to run your test against both netfx and netcoreapp you would need to add your test in the release/3.1 branch in dotnet/corefx repo. You can run the tests to make sure that there is a change in behavior between .net core and .net framework.

Read this two pages to learn how to run tests:

What you can also do is to write a console app targeting both netcoreapp and netfx that exercises your test case and share if there any behavioral differences.

maryamariyan avatar Feb 05 '20 18:02 maryamariyan

@maryamariyan I had already executed the instructions on the website https://github.com/dotnet/runtime/blob/master/docs/workflow/building/libraries/README.md but I followed the instructions suggested by @joperezr again and got the following results:

Discovering: System.Data.OleDb.Tests (method display = ClassAndMethod, method display options = None) Discovered: System.Data.OleDb.Tests (found 46 of 81 test cases) Starting: System.Data.OleDb.Tests (parallel test collections = on, max threads = 12) System.Data.OleDb.Tests.OleDbCommandBuilderTests.DeriveParameters_NullCommandText_Throws [SKIP] Condition(s) not met: "GetIsDriverAvailable" System.Data.OleDb.Tests.OleDbCommandBuilderTests.DeriveParameters_NullCommand_Throws [SKIP] Condition(s) not met: "GetIsDriverAvailable"

	..........
	..........
	
Finished:    System.Data.OleDb.Tests

=== TEST EXECUTION SUMMARY === System.Data.OleDb.Tests Total: 46, Errors: 0, Failed: 0, Skipped: 46, Time: 0,144s

LOG.zip

In Visual Studio / Test Explorer when running RUN ALL TESTS the result is 91 NOT RUN TESTS

Output: [05/02/2020 6:31:21.979 ] ---------- Discovery started ---------- Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.

  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited) em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) em Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler) [05/02/2020 6:31:22.047 ] ========== Discovery aborted: 0 tests found (0:00:00,0681689) ========== [05/02/2020 6:31:22.069 ] ---------- Run started ---------- O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.
  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. O processo do testhost foi encerrado com o erro: It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '5.0.0' was not found.
  • The following frameworks were found: 3.1.1 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The specified framework can be found at:
  • https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86 . Verifique os logs de diagnóstico para obter mais informações. [05/02/2020 6:31:22.176 ] ========== Run aborted: 0 tests run (0:00:00,1068654) ==========

jader1313 avatar Feb 05 '20 21:02 jader1313