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?

Anil Kocabiyik
  • 1,178
  • 6
  • 17
  • 47
  • 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}\InprocServer32 – Jonas Jan 05 '17 at 11:35
  • 1
    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. – Jonas Jan 05 '17 at 12:16
  • It also happens randomly on x64 too: CLR_EXCEPTION_REMOTE_System.AccessViolationException_NOSOS_System_Data!System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession – Brain2000 Jul 27 '20 at 16:45
  • @Jonas what guides are you talking about? I should like to consult them because I need to have both versions working. – Anton Shepelev Aug 11 '20 at 14:51

6 Answers6

9

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
Katia
  • 619
  • 6
  • 15
  • 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. – Brandon Barkley Jun 13 '16 at 20:09
  • 1
    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). – Mr Rubix Dec 12 '18 at 01:01
  • I still upvoted this answer because it specifies the cause of the error. – Anton Shepelev Aug 11 '20 at 14:52
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.

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.

Mike Lowery
  • 2,630
  • 4
  • 34
  • 44
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.

Jamie
  • 437
  • 4
  • 15
0

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

Annia Martinez
  • 2,442
  • 1
  • 12
  • 9
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.