The problem arises when you have your application compiled for AnyCPU Platform
, you are running on a 64bit system and the installed ADO.NET provider (Microsoft ACE.OLEDB.12.0) is the 32bit version.
When using the AnyCpu
target Platform 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.
The simplest workaround is to change the Target Platform of your application through Visual Studio menu
BUILD > Configuration > Active > Solution > Platform > x86
If the x86
option is not already there, then select NEW, name it x86
, Copy Settings from AnyCPU
and check Create new project platforms
If you think that using a 32bit app on a 64bit Operating System is a loss of performance or something to be avoided then think twice and read this reference where the PRO and CONS of AnyCpu are critically examined. If you don't have a specific reason to use AnyCpu
it is better to stay with x86
.
Of course, another option is to deinstall the 32bit version and install the 64bit version of ACE from hereand then run you application as AnyCpu on 64bit systems. But this could be a nightmare for your deployment scenarios. What about 32bit machine? What if Microsoft Office 32bit version is installed on your x64 target machine? Office installs its bit compatible version of ACE and, of course, it is not possible to have 32bit and 64bit of ACE installed on the same machine.
Now you should also ask your customer to reinstall Office as 64bit to keep your 64bit app happy.
(с) Steve
Original at stackoverflow