Saturday 22 January 2011

Microsoft.Jet.OLEDB.4.0 provider is not registered

The above message can and will show up using some software using Access databases on 64 bit Windows computers (Seven, Vista, 2008, XP 64..). It happened yesterday to a colleague of mine, and I had to investigate. The puzzling thing is that Jet is registered, and other software using it runs fine. Firing up task manager shows that the problematic .exe is running in 64 bit mode (no *32 suffix). There is no 64 bit Jet driver because it's old software and the 32 bit Jet engine runs fine. Why would one write a 64 bit software to use a nonexistent database driver?  Moreover, the same software on a 32 bit system runs flawlessly in 32 bit mode.

What is it? It's most probably .NET executable compiled with the 'AnyCPU' Project options. On a 32 bit system it runs in 32 bit mode and is able to use JET. On a 64 biti it runs in 64 bit mode, but it cannot use the non-existent 64 bit driver. Try this in Visual Studio, if you have it - it requires a single form and a single button:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;


namespace testaccess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;  Data Source=c:\\accessfile.mdb;";
  OleDbConnection cnn = new OleDbConnection(connectionString);
  cnn.Open();
        }
    }
}



Clicking the button will reproduce the problem on a 64 bit system. Obviously the solution is a recompile, if sources are available. Otherwise, there should be some way to force the executable in 32 bit mode, yeah?
Yeah, but it's not in .exe file properties, it's not something - as it would seem obvious - to put in a .manifest file along other things. It's a bit in the PE executable file. There is a Microsoft utility to do this: it's called CORFLAGS.EXE and to force a .NET executable to run in 32 bit mode it's usede this way:

CORFLAGS /32BIT+ filename.exe

To switch back to 64 bit mode:

CORFLAGS /32BIT- filename.exe

Where is CORFLAGS.EXE ? There doesn't seem to be an official download for the single file: that would be too simple, it's part of the latest SDKs (a few gigs to download). I got mine with Visual Studio, as I installed the .NET sdk. It's in %PROGRAMFILES%\Microsoft SDKs\Windows\v6.0A\bin"

Nota bene: make a backup of the original .exe anyway if it's not your software. Conceivably, using corflags.exe could conflict with some copy protection/activation schemes and render the software unworkable (though it's a bit unlikely).


No comments:

Post a Comment