OleDbConnection gets "External component has thrown an exception."
Asked Answered
A

6

16

I' m using a Windows Forms application to export data to excel.

Application is built both x64 and x86.

So both version of Microsoft Access Databse Engine must be installed to work the application on same computer.

Firstly AccessDatabaseEngine.exe is installed and AccessDatabaseEngine_x64.exe is installed passive.

x64 version of application is working

But x86 version is getting

SEHException: "External component has thrown an exception."

 at System.Data.Common.UnsafeNativeMethods.IDBInitializeInitialize.Invoke(IntPtr pThis)
 at System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr, SessionWrapper& sessionWrapper)
 at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
 at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
 at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
 at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
 at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
 at System.Data.OleDb.OleDbConnection.Open()

The code part is below;

var accessConnection = new OleDbConnection(connectionString);
accessConnection.Open();

And ConnectionString is

Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:\Users\Me\Desktop\ExportTest.xls";Extended Properties="Excel 8.0;HDR=Yes";

How can I solve it?

Animation answered 29/2, 2016 at 14:3 Comment(4)
I've been struggling with this myself now. Same scenario: Access DB Engine 2010 x86 & x64 installed since our app needs to support both. It first appeared in our OLEDB support of our C++ application, but confirmed in .NET too. I bet your SEH Exception code not seen by .NET is "Module not found". It seems to be some issue between 32/64-bit Access Engines, but here REGEDIT shows proper paths: (64-bit) HKEY_CLASSES_ROOT\CLSID\{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32 (32-bit) HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32Uriisa
Further investigation shows how it works while the x86 driver is installed. When x64 is then installed, it breaks the x86 version. But that's weird because it's supposed to work. Many guides show how to parallell install these, even if it's not officially supported by Microsoft.Uriisa
It also happens randomly on x64 too: CLR_EXCEPTION_REMOTE_System.AccessViolationException_NOSOS_System_Data!System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSessionHypodermic
@Uriisa what guides are you talking about? I should like to consult them because I need to have both versions working.Weasand
M
10

This will usually occur when the build configuration platform in Visual Studio is incorrect, this can occur in both build configuration platforms, x86 and x64.

This is due to a mismatch between the build configuration platform of your project and the Microsoft Access Database Engine which is installed on your machine.

In order to resolve this error:

  • Change the build configuration platform in Visual Studio
  • make sure it matches
  • the Microsoft Access Database Engine version on your machine
  • Recompile and run your project
  • The run time error should now be resolved
Mol answered 29/2, 2016 at 14:26 Comment(4)
Downvoted because the question explicitly says he has both versions installed and needs both versions. It is just the case that the 32-bit version is non-functional.Younker
I Had the same problem because i had installed the 64 Bits version after the 32 Bits Version. If you simply want to use the 32 bits version, i fixed the problem by uninstalling the AccessDataBaseEngine 64 bits (microsoft.com/en-in/download/details.aspx?id=13255) and then reinstalled the 32 bits version also availlable at (microsoft.com/en-in/download/details.aspx?id=13255).Calandracalandria
I still upvoted this answer because it specifies the cause of the error.Weasand
The fact is, the OLEDB 16.0 was replaced by a Windows Update on 8/8/2023. This answer would better serve if it explains how and what the update did to cause the issue in the first place. Updates include KB4486670 KB5002244 KB5002293 KB5002419 KB500211 - However, removing the 32 bit version of the Office 2016 does seem to resolve the issue. I am upvoting as the issue along with the comment address the 32 bit issue. SSIS fixes tend to be hard to find. This one works.Unwitting
L
3

I had the same error. It was fixed when I changed Provider=Microsoft.ACE.OLEDB.12.0; to Provider=Microsoft.ACE.OLEDB.16.0; I was running Office 2016.

Luzern answered 22/2, 2020 at 17:44 Comment(1)
In the connection string right? do you know root cause?Gca
H
1

In my case I had Office 2013 x64 installed. I then installed AccessDatabaseEngine2016_X64.exe after which I installed AccessDatabaseEngine2016.exe using the "/quiet" switch. I found that if I installed the x86 engine first I would get the error you're seeing, so order matters. I also changed my connection strings to Provider=Microsoft.ACE.OLEDB.16.0 (which appears to provide better OleDb error reporting).

You can verify driver installation using ODBC Data Sources.

Hollar answered 22/7, 2020 at 1:48 Comment(0)
U
0

I can propose a horrible solution but when you are under pressure, it works. Open the Excel file and save it as an xls file instead of xlsx. Install the ACEOLEDB.12 32 bit version and pull your data in that way. This is not the answer, but it may suffice as a work-around.

For most occasions, the "Flat File" import in SQL Server option will work just fine.

Unwitting answered 25/11, 2019 at 16:30 Comment(0)
H
0

I had similar problems and I reinstalled the Microsoft Access Database Engine, using the repair option. It worked for me.

Hibernal answered 25/2, 2020 at 19:39 Comment(0)
S
0

I have both 64 and 32 bit versions, and I had the same problem. I just went to the properties of the project and in the tab Build, I uncheck the box that says Prefer 32-bit.

Scurvy answered 22/4, 2020 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.