Import from excel error Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine

1.3k views Asked by At

i try to use ms interopt to import data from excel file, i have install Microsoft office 2007 in my computer and working fine, when i use the code in another computer have Microsoft office 2019 installed i face this error, i install

Microsoft Access Database Engine 2010 Redistributable 

but not fix the problem , also i search fro link of 2007 System Driver Data Connectivity Component, but i cannot find any one, and Microsft has remove the file, this is my code:

using System.Data.OleDb;
   OleDbConnection conn=null;
            DataTable ExcelDataTables = null;
            try { 
            
                  
         conn = new OleDbConnection();
        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties=" + "\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
                   conn.Open();
                   ExcelDataTables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                   String[] ExcelSheetNames = new String[ExcelDataTables.Rows.Count];
        int i = 0;

                   // Add the sheet name to the string array.
                   foreach (DataRow row in ExcelDataTables.Rows)
                   {
                    ExcelSheetNames[i] = row["TABLE_NAME"].ToString();//.Replace("'","").Replace("$", "");
        i++;
                   }

    // Loop through all of the sheets if you want too...
    /*for (int j = 0; j < excelSheets.Length; j++)
    {
        // Query each excel sheet.
    }*/

    conn.Close();
                conn = null;
         LSTBox_ExcelSheetNames.DataSource = ExcelSheetNames;
            }
            catch (Exception ex)
            {
                if (conn != null)
                    conn.Close();
                conn = null;

                ExcelDataTables = null;
                FRM_MSG f = new FRM_MSG();
                f.ShowDLG(" ",
                ex.Message + "\n" + ex.StackTrace.ToString(),
                            FRM_MSG.MSGIcon.Error,
                            FRM_MSG.BTNS.One,
                            new string[] { "Ok" });
            }

please give me a link to 2007 System Driver Data Connectivity Component.

2

There are 2 answers

3
Jeremy Thompson On

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

The documentation states MS Access drivers (including the OLEDB driver) only work under the x86 platform and is incompatible under the x64 or AnyCPU platform. However this appears to be untrue. Ref: https://stackoverflow.com/a/32760211/495455

First download the Microsoft Access Database Engine 2010 Redistributable making sure you tick the _64.exe version: http://www.microsoft.com/en-us/download/details.aspx?id=13255

  1. Extract the AccessDatabaseEngine_x64.exe to a folder to get the AceRedist.msi and Data.cab files.
  2. Open command prompt in Admin mode
  3. cd to the folder you extracted the download and execute the MSI with the passive argument:

AceRedist.msi /passive

After these steps you should be able to run the application after building in x64 or AnyCPU build configuration.

2
BymDeMon On

you can download AccessDatabaseEngine here! 2007 Office System Driver: Data Connectivity Components. https://download.cnet.com/2007-Office-System-Driver-Data-Connectivity-Components/3000-10254_4-75452798.html