Getting around Jet Engine not installed error on 64 bit Vista
There is a problem with 64 bit Vista and that is the Jet Engine, used by ADO.NETs OleDb Data Provider, is not supported. It's also no longer supported by Microsoft so a 64 bit version is not planned. If you develop with OleDb on 64 bit Vista you get an error saying something along the lines of the Jet Engine is not installed.
The solution to the problem is fairly straightforward and that is any application you write that uses OleDb should target the x86 CPU architecture. This forces your application to run in 32 bit mode. The application still runs in 64 bit under WOW64 so there is no problem. You change this setting using the Configuration Manager in Visual Studio or by compiling your application with the /platform:x86 switch.
This is fine for your own developments but what about applications you get that use OleDb and have been compiled with the AnyCPU option. With out source code your pretty much stuck, all OleDb calls will fail. However, after a bit of poking about in the invaluable MSDN library I came across one little piece of information that allows you to get around the problem.
On 64 bit Windows operating systems a DLL (read assembly) compiled with AnyCPU will execute on the same CLR as the process into which it is loaded. Interesting, because since an EXE file is also an assemby that means if you can load and execute an EXE in a process targetting the 32 bit CLR then you can get an compiled application, targeting AnyCPU and using OleDb, to run in 32 bit mode, meaning OleDb will work of 64 bit.
The good thing is you can do this with only a couple of lines of code.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ApplicationStarter
{
class Program
{
[STAThreadAttribute()]
static void Main(string[] args)
{
AppDomain.CurrentDomain.ExecuteAssembly(@"C:\Application.exe");
}
}
}
if you place the above into an console application and make that application ttarget the x86 architecture then the specified application is executed in the 32 bit process and any OleDb calls that are made will work, no need to recompile. You need to use the STAThreadAttribute as you'll get a runtime error if you don't.