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?