C# – The ‘Microsoft.Jet.OLEDB.4.0’ provider is not registered on the local machine

cnetoledb

Can someone help me with this error? When I try to open a connection to an mdb, I get "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine" error. How can I correct this?

My code is pretty simple:

class ImportTDB {
    private string filename;
    private string connectionString;

    private int collisions = 0;

    public ImportTDB(String filename) {
        this.filename = filename;
        this.connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename;
    }

    public void loadCustomerList() {
        DataTable dt = new DataTable();
        using (OleDbConnection conn = new OleDbConnection(connectionString)) {
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Names", conn);
            conn.Open();
            adapter.Fill(dt);
            conn.Close();
        }

        Console.WriteLine(dt.ToString());
    }
}

Best Answer

That's because there is no Jet driver for 64-bit systems and I suppose you are trying to run this on a x64 bit OS. You need to compile your program to target x86. In the project properties, Build tab, set Platform target to x86.