'Microsoft.ACE.OLEDB.12.0' provider is not

2018-12-31 02:48发布

I'm trying to get data from an Excel file on a button click event. My connection string is:

 string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\source\\SiteCore65\\Individual-Data.xls;Extended Properties=Excel 8.0;";

When I click on the button, I got the following error:

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

I have no clue how to fix this. My operating system is Windows 7.

30条回答
忆尘夕之涩
2楼-- · 2018-12-31 03:24

I installed the MS drivers and it still didn't work for me. Then I found this blog post that solved the issue. Read it there, else use these two images (linked from that post) as the TLDR sumamary:

enter image description here

enter image description here

查看更多
情到深处是孤独
3楼-- · 2018-12-31 03:25

Remember to install AccessDatabaseEngine on server for web application.

查看更多
零度萤火
4楼-- · 2018-12-31 03:27

For all those still affected by this.

I've been getting the error...

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

...as described by the OP, Shailesh Sahu.

I have 64bit Windows 7.

My problem is within PowerShell scripts, but is using a connection string, similar to the OP's post, so hopefully my findings can be applied to C#, PowerShell and any other language relying on the "Microsoft.ACE.OLEDB" driver.

I followed instructions on this MS forum thread: http://goo.gl/h73RmI

I first tried installing the 64bit version, then installing the 32bit version of the AccessDatabaseEngine.exe from this page http://www.microsoft.com/en-us/download/details.aspx?id=13255

But still no joy.

I then ran the code below in PowerShell (from SQL Panda's site http://goo.gl/A3Hu96)

(New-Object system.data.oledb.oledbenumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION 

...which gave me this result (I've removed other data sources for brevity)...

SOURCES_NAME              SOURCES_DESCRIPTION                                                                       
------------              -------------------                                                                       
Microsoft.ACE.OLEDB.15.0  Microsoft Office 15.0 Access Database Engine OLE DB Provider

As you can see, I have Microsoft.ACE.OLEDB.15.0 (fifteen) not Microsoft.ACE.OLEDB.12.0 (twelve)

So, I amended my connection string to 15 and it worked.

So, a quick PowerShell snippet to demonstrate how to soft-code the version...

$AceVersion = ((New-Object System.Data.OleDb.OleDbEnumerator).GetElements() | Where-Object { $_.SOURCES_NAME -like "Microsoft.ACE.OLEDB*" } | Sort-Object SOURCES_NAME -Descending | Select-Object -First 1 SOURCES_NAME).SOURCES_NAME

$connString = "Provider=$AceVersion;Data Source=`"$filepath`";Extended Properties=`"Excel 12.0 Xml;HDR=NO`";"

amended to pick the latest ACE version, if more than one

Hopefully, anyone finding this can now check to see what OLEDB version is installed and use the appropriate version number.

查看更多
几人难应
5楼-- · 2018-12-31 03:27

syp_dino,

The solution for me as you suggested for the "Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine" error is to change the Active Solution Platform from "Any CPU" to "x86".

When I performed those steps, rebuilt the solution, grabbed the EXE and placed in on the network, everything worked smoothly on the Windows 7 64 bit machine.

查看更多
君临天下
6楼-- · 2018-12-31 03:28

I got this error/exception in Visual Studio 2010 when I changed my build in the Configuration Manager dialog box from "x86" to "Any CPU". This OLEDB database driver I understand only works in x86 and is not 64bit compatible. Changing the build configuration back to x86 solved the problem for me.

查看更多
梦寄多情
7楼-- · 2018-12-31 03:31

I had the same issue but in this case microsoft-ace-oledb-12-0-provider was already installed on my machine and working fine for other application developed.

The difference between those application and the one with I had the problem was the Old Applications were running on "Local IIS" whereas the one with error was on "IIS Express(running from Visual Studio"). So what I did was-

  1. Right Click on Project Name.
  2. Go to Properties
  3. Go to Web Tab on the right.
  4. Under Servers select Local IIS and click on Create Virtual Directory button.
  5. Run the application again and it worked.
查看更多
登录 后发表回答