.net “Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6649363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:43:06  来源:igfitidea点击:

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

.netexcelaceoledb

提问by Shailesh Sahu

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

我正在尝试从按钮单击事件的 Excel 文件中获取数据。我的连接字符串是:

 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.

“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册。

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

我不知道如何解决这个问题。我的操作系统是 Windows 7。

回答by Variant

Well, you need to install it. You're looking for:

嗯,你需要安装它。您正在寻找:

回答by rsbarro

A 64-bit version of the 'Microsoft Access Database Engine 2010 Redistributable' that will allow you to use the 'Microsoft.ACE.OLEDB.12.0' provider is available here:
http://www.microsoft.com/en-us/download/details.aspx?id=13255

64 位版本的“Microsoft Access Database Engine 2010 Redistributable”将允许您使用“Microsoft.ACE.OLEDB.12.0”提供程序,请访问:http:
//www.microsoft.com/en-us/下载/details.aspx?id=13255

If you use the download from the accepted answer, you will need to build for x86, as pointed out by @backtestbroker.com.

如@backtestbroker.com 所指出的,如果您使用已接受答案的下载,则需要为 x86 构建。

回答by Bernhard

depending on the app(32/64bit) using the connection you could just install

根据使用连接的应用程序(32/64 位),您可以安装

Summary:

概括:

  • all offices from 2007-2016 contain the provider "Microsoft.ACE.Oledb.12.0"
  • depending on your application architecture choose the appropriate runtime engine (32/64)
  • check your providers with the powershell-command from both 32 and 64bit shell:

    (New-Object system.data.oledb.oledbenumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION 
    
  • and you will see which provider your system can use

  • 2007-2016 年的所有办公室都包含提供程序“Microsoft.ACE.Oledb.12.0”
  • 根据您的应用程序架构选择合适的运行时引擎 (32/64)
  • 使用32 位和 64 位 shell 中的 powershell-command 检查您的提供程序:

    (New-Object system.data.oledb.oledbenumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION 
    
  • 你会看到你的系统可以使用哪个提供商

the long story: the strings can be found with http://live.sysinternals.com/strings.exe

长篇大论:字符串可以通过http://live.sysinternals.com/strings.exe找到

eg. on a 64bit System with 32bit drivers installed

例如。在安装了 32 位驱动程序的 64 位系统上

strings.exe -u -n 10 "c:\Program Files (x86)\Common Files\microsoft shared\OFFICE12\MSO.DLL" | findstr "ACE.O"
strings.exe -u -n 10 "c:\Program Files (x86)\Common Files\microsoft shared\OFFICE14\MSO.DLL" | findstr "ACE.O"
strings.exe -u -n 10 "c:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\MSO.DLL" | findstr "ACE.O"

even in the upcoming office 2016

即使在即将到来的办公室 2016

c:\Program Files\Microsoft Office\root\VFS\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\MSO.DLL
c:\Program Files\Microsoft Office\root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\MSO.DLL

you will find the strings

你会发现字符串

  • Microsoft.ACE.OLEDB

  • Microsoft.ACE.Oledb.12.0

  • 微软ACE.OLEDB

  • 微软.ACE.Oledb.12.0

the Office 2013 comes also with csi.dll

Office 2013 也带有 csi.dll

c:\Program Files (x86)\Common Files\microsoft shared\OFFICE15\Csi.dll
c:\Program Files\Common Files\Microsoft Shared\OFFICE15\Csi.dll

which contains the "Microsoft.ACE.OLEDB.15.0"

其中包含“ Microsoft.ACE.OLEDB.15.0

and Office 2016

和 Office 2016

c:\Program Files\Microsoft Office\root\VFS\ProgramFilesCommonX64\Microsoft Shared\OFFICE16\Csi.dll
c:\Program Files\Microsoft Office\root\VFS\ProgramFilesCommonX86\Microsoft Shared\OFFICE16\Csi.dll

which has the "Microsoft.ACE.OLEDB.16.0" version

其中有“ Microsoft.ACE.OLEDB.16.0”版本

回答by Merav Kochavi

The first thing you need to check is your build configuration of your application.

您需要检查的第一件事是应用程序的构建配置。

  • If you have built your project under x86 platform, then in order to resolve you issue you should install the following packages on your machine:

    1. In order to use the 'Microsoft.ACE.OLEDB.12.0' provider you must install the Microsoft Access Database Engine 2010 Redistributablefirst, this installation is available at: http://www.microsoft.com/download/en/details.aspx?id=13255.

      After the installation has complete, try running you application, if this solves the issue great, if not, continue to step 2.

    2. This next step is an unexplained workaround, which works for Office 2010, even though it is the Data Connectivity Components of Office 2007. I am not quite sure why this works, but it does and this has been proven to work in almost all cases. You need to install the 2007 Office System Driver: Data Connectivity Components, this installation is available at: http://www.microsoft.com/download/en/confirmation.aspx?id=23734.

      After this installation is complete, try running your application, this should resolve the issue.

  • If you are trying to run an application built under x64 or AnyCPU platform, I would recommend first validating that it runs as expected under the x86 platform. In the event that it does not run under that x86 platform, perform the steps in the first part and validate that it runs as expected.

    I did read that the MS Access drivers including the OLEDB Database driver works only under the x86 platform and is incompatible under the x64 or AnyCPU platform. But this appears to be untrue. I validated my application was running when building x86, then I installed the Access Database Engine using the passive flag.

    1. First download the file locally You can download the installation here: http://www.microsoft.com/en-us/download/details.aspx?id=13255
    2. Installing using the command prompt with the '/passive' flag. In the command prompt run the following command: 'AccessDatabaseEngine_x64.exe /passive'

    After these 2 steps I managed to run my application after building in x64 or AnyCPU build configuration. This appeared to solve my issue.

  • 如果您已经在 x86 平台下构建了您的项目,那么为了解决您的问题,您应该在您的机器上安装以下软件包:

    1. 为了使用“Microsoft.ACE.OLEDB.12.0”提供程序,您必须先 安装 Microsoft Access Database Engine 2010 Redistributable,此安装位于:http: //www.microsoft.com/download/en/details.aspx ?id=13255

      安装完成后,尝试运行您的应用程序,如果这很好地解决了问题,如果没有,请继续第 2 步。

    2. 下一步是一个无法解释的解决方法,它适用于 Office 2010,即使它是 Office 2007 的数据连接组件。我不太确定为什么会这样,但确实如此,而且这已被证明在几乎所有情况下都有效。您需要安装 2007 Office System Driver: Data Connectivity Components,该安装程序位于:http: //www.microsoft.com/download/en/confirmation.aspx?id=23734

      安装完成后,尝试运行您的应用程序,这应该可以解决问题。

  • 如果您尝试运行在 x64 或 AnyCPU 平台下构建应用程序,我建议首先验证它在 x86 平台下是否按预期运行。如果它不在该 x86 平台下运行,请执行第一部分中的步骤并验证它是否按预期运行。

    我确实读过包括 OLEDB 数据库驱动程序在内的 MS Access 驱动程序仅在 x86 平台下工作,在 x64 或 AnyCPU 平台下不兼容。但这似乎是不真实的。我在构建 x86 时验证了我的应用程序正在运行,然后我使用被动标志安装了 Access 数据库引擎。

    1. 首先将文件下载到本地可以在这里下载安装:http: //www.microsoft.com/en-us/download/details.aspx?id=13255
    2. 使用带有“/passive”标志的命令提示符进行安装。 在命令提示符下运行以下命令:'AccessDatabaseEngine_x64.exe /passive'

    在这两个步骤之后,我在 x64 或 AnyCPU 构建配置中构建后设法运行我的应用程序。这似乎解决了我的问题。

Note: The order of the steps seems to make a difference, so please follow accordingly.

注意:步骤的顺序似乎有所不同,因此请相应地遵循。

回答by timodius

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.

当我将 Configuration Manager 对话框中的构建从“x86”更改为“Any CPU”时,我在 Visual Studio 2010 中遇到此错误/异常。我了解的这个 OLEDB 数据库驱动程序仅适用于 x86,并且不兼容 64 位。将构建配置更改回 x86 解决了我的问题。

回答by Shaul Behr

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

我安装了 MS 驱动程序,但它仍然不适合我。然后我发现这篇博文解决了这个问题。在那里阅读,否则使用这两个图像(从该帖子链接)作为 TLDR 摘要:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Aximili

If you're using 64-bit but still having problem even after installing AccessDatabaseEngine, see this post, it solved the problem for me.

如果您使用的是 64 位,但即使在安装 AccessDatabaseEngine 后仍有问题,请参阅此帖子,它为我解决了问题。

i.e. You need to install thisAccessDatabaseEngine

即你需要安装这个AccessDatabaseEngine

回答by TechSpud

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.

...正如 OP 所描述的,Shailesh Sahu。

I have 64bit Windows 7.

我有 64 位 Windows 7。

My problem is within PowerShellscripts, 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.

我的问题出在PowerShell脚本中,但使用的是连接字符串,类似于 OP 的帖子,因此希望我的发现可以应用于 C#、PowerShell 和依赖“Microsoft.ACE.OLEDB”驱动程序的任何其他语言。

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

我按照此 MS 论坛主题的说明进行操作:http: //goo.gl/h73RmI

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

我首先尝试安装64 位版本,然后从此页面安装32 位版本的 AccessDatabaseEngine.exe 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)

然后我在PowerShell 中运行下面的代码(来自 SQL Panda 的站点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)

如您所见,我有 Microsoft.ACE.OLEDB。15.0(十五)不是 Microsoft.ACE.OLEDB。12.0(十二)

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

所以,我将我的连接字符串修改为 15 并且它起作用了。

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

所以,一个快速的 PowerShell 片段来演示如何对版本进行软编码......

$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

修改为选择最新的 ACE 版本,如果不止一个

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

希望任何发现此问题的人现在都可以检查安装的 OLEDB 版本并使用适当的版本号。

回答by josh

Although many answers have been given, the problem I encountered was not yet mentioned.

虽然已经给出了很多答案,但是我遇到的问题还没有提到。

  • My Scenario:64-Bit Application, Win10-64, Office 2007 32-Bit installed.
  • Installation of the 32-Bit Installer AccessDatabaseEngine.exeas downloaded from MS reports success, but is NOT installed, as verified with the Powershell Script of one of the postings above here.

  • Installation of the 64-Bit installer AccessDatabaseEngine_X64.exereported a shocking error message:

  • 我的场景:64 位应用程序,Win10-64,Office 2007 32 位安装。
  • 从 MS 下载的 32 位安装程序AccessDatabaseEngine.exe 的安装 报告成功,但未安装,如以上帖子之一的 Powershell 脚本所验证。

  • 安装 64 位安装程序AccessDatabaseEngine_X64.exe报告了令人震惊的错误消息:

enter image description here

在此处输入图片说明

The very simple solution has been found hereon an Autodesk site. Just add the parameter /passive to the commandline string, like this:

在 Autodesk 网站上找到非常简单的解决方案。只需将参数 /passive 添加到命令行字符串中,如下所示:

AccessDatabaseEngine_X64.exe /passive

AccessDatabaseEngine_X64.exe /passive

Installation successful, the OleDb driver worked.

安装成功,OleDb 驱动工作正常。

The Excel files I am processing with OleDb are of xlsx type, produced with EPPlus 4.5 and modified with Excel 2007.

我使用 OleDb 处理的 Excel 文件是 xlsx 类型,使用 EPPlus 4.5 生成并使用 Excel 2007 修改。

回答by mohit busa

You need to change the Solution Platform from "Any CPU" to "x86" or "x64" based on the bitness of office installation.

您需要根据办公安装的位数将解决方案平台从“Any CPU”更改为“x86”或“x64”。

The steps are given below:

步骤如下:

  1. Right click on the Solution File in Solution Explorer: enter image description here

    1. Click on the Configuration Manager.
    2. Click on the Active Platform Drop down, if x86 is already there then select that, else click on New. enter image description here

    3. Select x86 or x64 from the new platform dropdown: enter image description here

  1. 在解决方案资源管理器中右键单击解决方案文件: 在此处输入图片说明

    1. 单击配置管理器。
    2. 单击 Active Platform 下拉菜单,如果 x86 已经存在,则选择它,否则单击 New。 在此处输入图片说明

    3. 从新平台下拉列表中选择 x86 或 x64: 在此处输入图片说明

Compile and run your application.

编译并运行您的应用程序。