OleDbConnection得到“外部组件引发了异常". [英] OleDbConnection gets "External component has thrown an exception."

查看:598
本文介绍了OleDbConnection得到“外部组件引发了异常".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Forms应用程序将数据导出到excel.

I' m using a Windows Forms application to export data to excel.

应用程序是同时构建于x64和x86上的.

Application is built both x64 and x86.

因此必须同时安装两个版本的Microsoft Access Databse Engine才能在同一台计算机上使用该应用程序.

So both version of Microsoft Access Databse Engine must be installed to work the application on same computer.

首先安装AccessDatabaseEngine.exe 并且AccessDatabaseEngine_x64.exe是被动安装的.

Firstly AccessDatabaseEngine.exe is installed and AccessDatabaseEngine_x64.exe is installed passive.

x64版本的应用程序正在运行

x64 version of application is working

但是x86版本正在

SEHException: "External component has thrown an exception."

 at System.Data.Common.UnsafeNativeMethods.IDBInitializeInitialize.Invoke(IntPtr pThis)
 at System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr, SessionWrapper& sessionWrapper)
 at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
 at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
 at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
 at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
 at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
 at System.Data.OleDb.OleDbConnection.Open()

代码部分在下面;

var accessConnection = new OleDbConnection(connectionString);
accessConnection.Open();

而ConnectionString是

And ConnectionString is

Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:\Users\Me\Desktop\ExportTest.xls";Extended Properties="Excel 8.0;HDR=Yes";

我该如何解决?

推荐答案

通常会在Visual Studio中的构建配置平台不正确时发生,在x86和x64两种构建配置平台中都可能发生.

This will usually occur when the build configuration platform in Visual Studio is incorrect, this can occur in both build configuration platforms, x86 and x64.

这是由于项目的构建配置平台与计算机上安装的Microsoft Access数据库引擎之间不匹配.

This is due to a mismatch between the build configuration platform of your project and the Microsoft Access Database Engine which is installed on your machine.

为了解决此错误:

  • 在Visual Studio中更改构建配置平台
  • 确保它匹配
  • 计算机上的Microsoft Access数据库引擎版本
  • 重新编译并运行项目
  • 现在应该解决运行时错误

这篇关于OleDbConnection得到“外部组件引发了异常".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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