Hi Jonathan Riley
As far as I know, this is the conflict between Office Click-to-Run (C2R) and the standalone ACE redistributable occurs in two stages:
Office C2R uses a virtualized COM environment. When the standalone ACE redistributable is installed, both compete for the Microsoft.ACE.OLEDB.16.0 registry key. Frequent Office updates consistently overwrite the redistributable’s entries, causing the system to load conflicting binaries (like the unstable mso98win32client.dll shim).
The 0xC0000005 access violation happens during process termination. The .NET finalizer thread attempts to release COM wrappers (RCWs) while the native OS is simultaneously unloading the underlying DLLs. This creates a use-after-free error as .NET tries to communicate with a memory address that has already been cleared.
Given this context, you can try two workaround options below first and let me know the results:
Option 1:
Explicitly release the connection pool and force a full GC cycle before the process exits. This ensures all COM RCWs are released while the native libraries are still alive.
Imports System.Data.OleDb
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=[PATH TO accdb]"
Try
DoWork(connectionString)
Finally
' Critical: flush the OleDb connection pool and force COM cleanup
' BEFORE the runtime begins its shutdown sequence
OleDbConnection.ReleaseObjectPool()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Sub
Private Sub DoWork(connectionString As String)
Using conn As New OleDbConnection(connectionString)
conn.Open()
Console.WriteLine("Connection Open!")
' ... do work ...
End Using ' Dispose is called here automatically
Console.WriteLine("Connection Closed!")
End Sub
End Module
Option 2: Switch from OLEDB to ODBC
To use this, you would switch your imports to System.Data.Odbc:
Imports System.Data.Odbc
Module Module1
Sub Main()
' Use the ODBC driver instead of OLEDB
Dim connectionString As String = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=[PATH TO accdb];"
Dim conn As New OdbcConnection(connectionString)
If conn Is Nothing Then
Throw New Exception("Error creating database Connection")
End If
Try
conn.Open()
Console.WriteLine("Connection Open!")
Catch e As Exception
Console.WriteLine("Error: " & e.Message)
Throw e
Finally
If conn IsNot Nothing Then
If conn.State <> ConnectionState.Closed Then
conn.Close()
Console.WriteLine("Connection Closed!")
End If
conn.Dispose()
End If
End Try
End Sub
End Module
Hope my answer will help you.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.