1
votes

We've discovered that if we read from an Excel file using the Microsoft.ACE OLEDB provider from a 64-bit machine with a 32-bit version of Office installed, it will throw an exception if built for platform "AnyCPU".

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

The solutions posted here all seem to be about changing your build platform to x86, or installing 64-bit data access components on the user's machine, neither of which are an ideal solution for us.

Is there any other way via the c# code to ensure that it reads the 32-bit version of the OLEDB data provider?

Example code :

string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test.xlsx;Extended Properties=Excel 8.0;";

using(OleDbConnection connection = new OleDbConnection(connString))
{
    connection.Open(); // exception here
}
1

1 Answers

0
votes

Short answer is No, there isn't. When using AnyCpu your code will be executed as 64bit code on 64bit systems and as 32bit code on 32bit systems. An application executed as 64bit cannot use 32bit drivers (and viceversa). The Microsoft.ACE.OLEDB.12.0 has two different version for 64 and 32bit that cannot be installed together on the same machine. Therefore the best solution is to compile your code to x86 or x64 depending on the drivers available on the machine.