Reading xlsx file in c# using OleDbConnection thro

2019-07-19 15:17发布

I wrote a console application to read the xlsx file in C# using OleDbConnection. It throws the following error

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

Below is the code i have written

string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Suganya\ColumnReport.xlsx;Extended Properties=Excel 12.0;";
OleDbConnection objConn = new OleDbConnection();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
objConn = new OleDbConnection(connString);

string Query = "SELECT * FROM [Sheet1$]";
OleDbCommand objCmd = new OleDbCommand(Query, objConn);

DataTable Table = new DataTable();
dataAdapter.SelectCommand = objCmd;
dataAdapter.Fill(Table);

I have already performed following things to fix the issue.

  1. I have installed AccessDatabaseEngine.exe (32 bit) and found that ACEOLEDB.dll is present in the following path C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14

  2. Tried referring the ACEOLEDB.dll in the application. But it gave me the following error

    A reference to 'ACEOLEDB.DLL' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

  3. The configuration platform of console application is of 32 Bit

Environment Details

  1. Windows Server 2008 (64 bit)
  2. Visual Studio 2010 ( 32 bit)
  3. MS office is not installed

Checked the following links to fix the issue

1.http://www.codeproject.com/Questions/486549/Theplus-27Microsoft-ACE-Oledb-12-0-27plusproviderp 2.http://www.codeproject.com/Questions/337953/The-Microsoft-ACE-OLEDB-12-0-provider-is-not-regis

Any help is highly appreciated.

标签: c# excel oledb
1条回答
祖国的老花朵
2楼-- · 2019-07-19 15:36

You have to install Microsoft Office; Office installation process will copy and register the wished assemblies ('ACEOLEDB.DLL') in the GAC, or you can add the missing assemblies in your bin (application) directory or regsiter them by your self.

查看更多
登录 后发表回答