将数据导出到 MS ACCESS 时,“Microsoft.ACE.OLEDB.12.0"提供程序未在本地计算机上注册 [英] The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine while data export to MS ACCESS

查看:25
本文介绍了将数据导出到 MS ACCESS 时,“Microsoft.ACE.OLEDB.12.0"提供程序未在本地计算机上注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用 Microsft.ACE.OLEDB 12.0 的初学者.我创建了一个 Winforms 应用程序 VS 2010.

I am beginner in using Microsft.ACE.OLEDB 12.0. I create a Winforms application VS 2010.

并创建将数据网格数据导出到 MS Access 文件的功能.我使用的是 Microsoft Oledb

And create a function for export data grid data to MS Access file. I using Microsoft Oledb

用于将数据网格数据导出到 MS Access 文件.但是当我尝试导出时出现此错误

for export the data grid data to MS Access file.But i get this error when i try to export

数据到毫秒访问.

请看下图.

我还在我的应用程序中引用了 Microsoft.Office 12.0 对象库.

I also refer the Microsoft.Office 12.0 Object Library in my application.

批量构建配置

推荐答案

Access Interop 位的引用与您的异常无关,并且 Access Interop 不需要使用System.Data.OleDb.

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.

当您为 AnyCPU 平台 编译应用程序时,会出现问题,您在 64 位系统上运行并且安装的 ADO.NET 提供程序 (Microsoft ACE.OLEDB.12.0) 是 32 位版本.

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 目标平台时,您的代码将在 64 位系统上作为 64 位代码执行,在 32 位系统上作为 32 位代码执行.作为 64 位执行的应用程序不能使用 32 位驱动程序(反之亦然).现在添加一个事实,即 Microsoft.ACE.OLEDB.12.0 有两个不同的版本.一个用于 64 位,一个用于 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.

最简单的解决方法是通过 Visual Studio 菜单更改应用程序的目标平台

The simplest workaround is to change the Target Platform of your application through Visual Studio menu

 BUILD -> Configuration Manager -> Active Solution Platform -> x86

如果 x86 选项不存在,则选择 NEW,将其命名为 x86Copy Settings from AnyCPU 并检查 创建新的项目平台

If the x86 option is not already there, then select NEW, name it x86, Copy Settings from AnyCPU and check Create new project platforms

如果您认为在 64 位操作系统上使用 32 位应用会导致性能损失或需要避免的事情,那么请三思并阅读 这个参考 其中 AnyCpu 的优点和缺点是严格审查.如果您没有使用 AnyCpu 的特定理由,最好继续使用 x86.

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 reference where 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.

当然,另一个选择是卸载 32 位版本并安装 64 位版本的 ACE 从这里,然后在 64 位系统上将您的应用程序作为 AnyCpu 运行.但这对于您的部署场景来说可能是一场噩梦.如果您的 x64 目标机器上安装了 Microsoft Office 32 位版本怎么办?Office 安装了其位兼容版本的 ACE,并且如上所述,不可能在同一台机器上安装 32 位和 64 位的 ACE.
现在,您还应该要求您的客户将 Office 重新安装为 64 位,以使您的 64 位应用程序满意.

Of course, another option is to deinstall the 32bit version and install the 64bit version of ACE from here and 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.

更新


使用最新版本的 Visual Studio,情况有所改变.现在有一个新选项是新项目的默认选项.它被称为AnyCPU Prefer 32bit mode.此链接的更多详细信息:AnyCPU 在 .NET 4.5 和 Visual Studio 11 中的真正含义 和另一个有趣的帖子(尽管是关于 Sql Server Compact)是这个 任何 CPU 的问题–首选 32 位–BadImageFormatException

UPDATE


The situation has changed a bit with the newest versions of Visual Studio. There is now a new option that is the default for new projects. It is called AnyCPU Prefer 32bit mode. More details at this link: What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11 and another interesting post (albeit regarding Sql Server Compact) is this one The trouble with Any CPU–Prefer 32 bit–BadImageFormatException

这篇关于将数据导出到 MS ACCESS 时,“Microsoft.ACE.OLEDB.12.0"提供程序未在本地计算机上注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆