0

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.

Fath Bakri
  • 161
  • 1
  • 12
  • Are you using the aceoledb driver to import files?yes , i use it to get sheets name,Does the Access DB Engine 2010 Redist supposed fix the error message that we cannot see? No, the error message Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine – Fath Bakri Jul 05 '22 at 03:24
  • all i need is a link to 2007 office System Driver Data Connectivity Components – Fath Bakri Jul 05 '22 at 12:16

2 Answers2

1

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.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
0

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

BymDeMon
  • 11
  • 4