Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
916 views
in Technique[技术] by (71.8m points)

c# - OleDbConnection gets "External component has thrown an exception."

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

Application is built both x64 and x86.

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

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

x64 version of application is working

But x86 version is getting

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()

The code part is below;

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

And ConnectionString is

Provider=Microsoft.ACE.OLEDB.12.0;Data Source="C:UsersMeDesktopExportTest.xls";Extended Properties="Excel 8.0;HDR=Yes";

How can I solve it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

In order to resolve this error:

  • Change the build configuration platform in Visual Studio
  • make sure it matches
  • the Microsoft Access Database Engine version on your machine
  • Recompile and run your project
  • The run time error should now be resolved

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...