Friday, September 21, 2007

Access MDB on windows 64 bit using C#

Few days ago I had to install software I wrote in C# which uses Access MDB files on a Windows 2003 x64. After installing the software (compiled for 32bit) I got an error saying the Microsoft.Jet.OLEDB.4.0 provider is not installed.

After a short search I found out there isn't JET provider for x64 systems, however, Windows 2003 comes with 2 sets of ODBC providers: 64bit and 32bit, which can be accessed with 2 separate programs:
c:\windows\SysWOW64\odbcad.exe - 32bit providers
c:\windows\system\odbcad.exe - 64bit providers

When checking the list of x32 providers I found Access MDB provider! So at this point I started to check how to force .NET applications to run in x32 mode. 5 minutes later I had the solution - the .NET SDK utility CorFlags.exe:

CorFlags /32bit+ MyProgram.exe

Works like a charm. Now my program runs as before with Access MDB on Windows 2003 x64.

UPDATE: Better solution with the same results -
Project -> Properties -> Build
Set "Platform Target" to x86

No comments: