C# 将数据导出到 MS ACCESS 时,“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17716207/
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
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine while data export to MS ACCESS
提问by Ragesh S
I am beginner in using Microsft.ACE.OLEDB 12.0. I create a Winforms application VS 2010.
我是使用 Microsft.ACE.OLEDB 12.0 的初学者。我创建了一个 Winforms 应用程序 VS 2010。
And create a function for export data grid data to MS Access file. I using Microsoft Oledb
并创建将数据网格数据导出到 MS Access 文件的功能。我使用 Microsoft Oledb
for export the data grid data to MS Access file.But i get this error when i try to export
用于将数据网格数据导出到 MS Access 文件。但是当我尝试导出时出现此错误
the
这
data to ms access.
数据到ms访问。
Please see the below image.
请看下图。
I also refer the Microsoft.Office 12.0 Object Libraryin my application.
我还在我的应用程序中引用了Microsoft.Office 12.0 对象库。
Batch Build Configuration
批量构建配置
采纳答案by Steve
The reference to the Access Interop
bits has nothing to do with your exception and Access Interop is not necessary to use the classes in the System.Data.OleDb
.
对Access Interop
位的引用与您的异常无关,并且 Access Interop 不需要使用System.Data.OleDb
.
The problem arises when you have your application compiled for AnyCPU Platform
, you are running on a 64bit system and the installed ADO.NET provider (Microsoft ACE.OLEDB.12.0) is the 32bit version.
当您为 编译您的应用程序AnyCPU Platform
,您在 64 位系统上运行并且安装的 ADO.NET 提供程序 (Microsoft ACE.OLEDB.12.0) 是 32 位版本时,就会出现问题。
When using the AnyCpu
target Platform your code will be executed as 64bit code on 64bit systems and as 32bit code on 32bit systems. An application executed as 64bit cannot use 32bit drivers (and viceversa). Now add to the mix the fact that Microsoft.ACE.OLEDB.12.0 has two different versions. One for 64bit and and one for 32bit and they cannot be installed together on the same machine.
使用AnyCpu
目标平台时,您的代码将在 64 位系统上作为 64 位代码执行,在 32 位系统上作为 32 位代码执行。作为 64 位执行的应用程序不能使用 32 位驱动程序(反之亦然)。现在添加一个事实,即 Microsoft.ACE.OLEDB.12.0 有两个不同的版本。一个用于 64 位,一个用于 32 位,它们不能一起安装在同一台机器上。
The simplest workaround is to change the Target Platform of your application through Visual Studio menu
最简单的解决方法是通过 Visual Studio 菜单更改应用程序的目标平台
BUILD -> Configuration Manager -> Active Solution Platform -> x86
If the x86
option is not already there, then select NEW, name it x86
, Copy Settings from AnyCPU
and check Create new project platforms
如果该x86
选项尚不存在,则选择 NEW,将其命名为x86
,Copy Settings from AnyCPU
然后检查Create new project platforms
If you think that using a 32bit app on a 64bit Operating System is a loss of performance or something to be avoided then think twice and read this referencewhere the PRO and CONS of AnyCpu are critically examined. If you don't have a specific reason to use AnyCpu
it is better to stay with x86
.
如果您认为在 64 位操作系统上使用 32 位应用程序会导致性能损失或需要避免的事情,那么请三思并阅读此参考资料,其中对 AnyCpu 的优点和缺点进行了严格检查。如果您没有特定的使用理由,AnyCpu
最好继续使用x86
.
Of course, another option is to deinstall the 32bit version and install the 64bit version of ACE from hereand then run you application as AnyCpu on 64bit systems. But this could be a nightmare for your deployment scenarios. What if Microsoft Office 32bit version is installed on your x64 target machine? Office installs its bit compatible version of ACE and, as said, it is not possible to have 32bit and 64bit of ACE installed on the same machine.
Now you should also ask your customer to reinstall Office as 64bit to keep your 64bit app happy.
当然,另一种选择是卸载 32 位版本并从此处安装 64 位版本的 ACE ,然后在 64 位系统上将应用程序作为 AnyCpu 运行。但这对于您的部署场景来说可能是一场噩梦。如果您的 x64 目标机器上安装了 Microsoft Office 32 位版本怎么办?Office 安装其位兼容版本的 ACE,并且如上所述,不可能在同一台机器上安装 32 位和 64 位的 ACE。
现在,您还应该要求您的客户将 Office 重新安装为 64 位,以使您的 64 位应用程序满意。
UPDATE
更新
使用最新版本的 Visual Studio,情况有所改变。现在有一个新选项是新项目的默认选项。它被称为AnyCPU Prefer 32bit modeAnyCPU 首选 32 位模式。此链接的更多详细信息:What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11AnyCPU 在 .NET 4.5 和 Visual Studio 11 中的真正含义以及另一个有趣的帖子(尽管是关于 Sql Server Compact)是这个The trouble with Any CPU–Prefer 32 bit–BadImageFormatExceptionAny CPU 的问题——首选 32 位——BadImageFormatException
回答by Freguz
Change in its App pool 'advanced settings' to allow to run 32-bit programs... that did it for me.
更改其应用程序池“高级设置”以允许运行 32 位程序......这对我来说是这样的。
回答by Rahul Techie
I have similar issue when we are reading Excel file.
当我们阅读 Excel 文件时,我遇到了类似的问题。
History of the problem:
问题历史:
We recently migrated our application from 32-bit to 64-bit because of the memory requirement. For that we migrated our windows 7 from 32-bit to 64-bit. But still we installed 32-bit office on our machines.
由于内存要求,我们最近将应用程序从 32 位迁移到 64 位。为此,我们将 Windows 7 从 32 位迁移到 64 位。但是我们仍然在我们的机器上安装了 32 位 Office。
because, of this we had this issue while importing Excel data into application.
因为,因此我们在将 Excel 数据导入应用程序时遇到了这个问题。
Solution,
解决方案,
I downloaded 64-bit version of the http://www.microsoft.com/en-us/download/details.aspx?id=13255and installed with argument as,
我下载了http://www.microsoft.com/en-us/download/details.aspx?id=13255 的64 位版本并使用参数安装,
AccessDatabaseEngine_x64.exe /passive
AccessDatabaseEngine_x64.exe /passive
Without any code change my issue get resolved.
没有任何代码更改我的问题得到解决。
Note:
笔记:
On 64-bit OS and 64-bit office, my functionality was working fine without this fix. This fix is only required while our application is 64-bit running on 64-bit OS which is having 32-bit office installed on it.
在 64 位操作系统和 64 位办公室上,我的功能在没有此修复程序的情况下运行良好。仅当我们的应用程序在 64 位操作系统上运行 64 位时才需要此修复,该操作系统上安装了 32 位办公室。
回答by Joh
Base way:
基本方式:
Application : MVC C#
,
For Win Server 64 bit:
应用 : MVC C#
, 对于 Win Server 64 位:
Remove all office 32 bit installed.
Download link: https://www.microsoft.com/en-us/download/details.aspx?id=13255
select download 64 bit and then install it to server(If you can't setup program. Please re-check 1 point).
retry access your application again.enter image description here
删除所有安装的 office 32 位。
下载链接:https: //www.microsoft.com/en-us/download/details.aspx?id=13255
选择下载 64 位然后安装到服务器(如果你不能安装程序,请重新检查 1 点)。
重试再次访问您的应用程序。在此处输入图片说明
回答by Erik Pienknagura Dolberg
for me installing Microsoft Access Database Engine 2010 Redistributable fixed the problem, the 32 bit version.
对我来说,安装 Microsoft Access Database Engine 2010 Redistributable 解决了 32 位版本的问题。