DanG
DanG

Reputation: 93

ACE Driver Works in VBA but not C# - Why?

I want to know why the ACE Driver works in VBA when I want to read an Excel (VBA) file but fails when I try it in Visual Studio Code (C#).

I know that you need to install the Access Runtime to get the ACE Drivers, but this is not possible without Admin rights. I also know that you can use the Interop to read Excel files with C#. I just want to understand why the basically same code in VBA works but doesn't work in C#.

This works in VBA:

connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & filePath & _
      "; Extended Properties='Excel 12.0 Xml;HDR=YES';"
    connection.Open connString

But this fails in C#:

string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + @";Extended Properties='Excel 12.0;HDR=Yes;'";  
using(OleDbConnection connection = new OleDbConnection(connectionString))
{
   connection.Open();
}

When I run the C# I get the The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine error'

I have dealt with this issue before, but would love someone who understands it better to help out. Is it the ActiveX reference in Excel? Can I someone access this without using the Interop?

Upvotes: 0

Views: 94

Answers (0)

Related Questions