0

After a lots of googling on the internet and reading a lots of post I could not handle my case and please before mark this post as a duplicate please read to end.

I have a machine with:

  • Office 2019 package (Excel)

  • visual studio 2019 enterprise edition

  • Windows 10 (X64) enterprise edition

and want to read a simple excel file with a c# windows application but it does not work.

Error:

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

I know this is a common prob and after searching a lot,I installed these file on my computer but it didn't fixed my error.

Microsoft Access Database Engine 2010 Redistributable x64 edition

Microsoft Access 2010 Runtime x64 edition

And Codes:

 DataTable rs = new DataTable();

 using (var odConnection = new 
        OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data 
         Source=c:\myfile.xlsx;Extended Properties='Excel 
                 12.0;HDR=YES;IMEX=1;';"))
        {
            odConnection.Open();//Error, when wants to open the connection

            using (OleDbCommand cmd = new OleDbCommand())
            {
                cmd.Connection = odConnection;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT * FROM [Sheet1$]";
                using (OleDbDataAdapter oleda = new OleDbDataAdapter(cmd))
                {
                    oleda.Fill(rs);
                }
            }
            odConnection.Close();
        }

I tested another source codes but got the same error,whats wrong whit this is it because of office 2019 or visual studio or must install something on my machine?

Mikku
  • 6,538
  • 3
  • 15
  • 38
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108
  • 1
    Is it really `xlxs` ? or `xlsx` ? – Mikku Aug 28 '19 at 10:31
  • Its should be xlsx not xlxs . xlxs is not any extension – Naveen Aug 28 '19 at 10:33
  • Are you bound to an OLE connection or can you use anything to read the file? I've used https://spreadsheetlight.com/ with xlsx files, though not with the 2019 version. – Markus Deibel Aug 28 '19 at 10:34
  • @Mikku yes I made it by myself on Excel, it's .xlsx – motevalizadeh Aug 28 '19 at 10:38
  • Okay ... I will change it in your Question Heading :) – Mikku Aug 28 '19 at 10:43
  • @Mikku oh sorry , Thanks – motevalizadeh Aug 28 '19 at 10:46
  • Try searching your registry for "Microsoft.ACE.OLEDB" if you haven't already. FWIW I only have it in "HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Classes\Microsoft.ACE.OLEDB.12.0" i.e. in a separate Office ClickToRun space and not actually in HKCR. I'm not sure how you use the 'ClickToRun' part here: https://superuser.com/a/1270517/39645 If you do want to Excel to open this file then you may have interop assemblies installed that are set up to use this setup, but you'd need to use Excel objects not the OLEDB driver. – Rup Aug 28 '19 at 10:53
  • 2
    There are plenty of libraries you can use to open XLSX files without actually using Excel though, e.g. many listed here https://stackoverflow.com/q/151005 – Rup Aug 28 '19 at 10:54
  • Make sure to build for AnyCPU or x64. – James John McGuire 'Jahmic' Sep 01 '19 at 11:39

0 Answers0