Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can .NET app run with 32bit and 64bit Office?

I have a Windows 64bit system, and a C# app that uses an OleDbConnection to read Excel data via the 32bit version of AccessDatabaseEngine.exe COMponents since I have Office 32bit installed (as recommended by MSFT), and the 64bit version of AccessDatabaseEngine would not work with 32bit Office.

In order to get my C# app to work, I had to set "Prefer 32-bit" in the project build settings. This sets the compiler /platform anycpu32bitpreferred flag. There is no "preferred" about this on Intel platforms.

So everything runs fine. On my machine. Not on my boss' 64bit machine where he installed 64 bit Office.

I cannot find any app.config option to force 64bit. Is there one? Is it theoretically possible in the .NET load sequence that there could be one?

MSFT did not think this through. I should somehow be able to build an app that can work with both 32 and 64 bit versions of Office. Can I somehow using OleDbConnection?

I know about the CorFlags.exe /32bitpref- flag but this requires maintaining two versions of the binary.

Any ideas? Fixes? App.Config options?

like image 565
Dave Avatar asked Oct 21 '22 18:10

Dave


1 Answers

You need to download the 64 bit version of the ODBC driver (it says access but it does excel driver too).

You will likely get a error saying you can not have both 32 bit and 64 bit installed at the same time, to get around this you must use the /passive flag

To install the Microsoft ACE OLEDB Provider 32-bit on a machine running Office 2010 64-bit:

  • AccessDatabaseEngine.exe /passive

To install the Microsoft ACE OLEDB Provider 64-bit on a machine running Office 2010 32-bit:

  • AccessDatabaseEngine_X64.exe /passive
like image 123
Scott Chamberlain Avatar answered Oct 31 '22 16:10

Scott Chamberlain