Querying Jet Databases/Excel files with C# under x64 OS

最后都变了- 提交于 2019-12-10 10:24:14

问题


So I have learned that that the Microsoft.Jet.OLEDB.4.0 data provider for querying data sources like Microsoft Access MDB files and Excel spreadsheets does not work under a Windows 64-bit operating systems.

What I am now supposed to use to query against these file types in .NET 3.5 (C#) applications in order to ensure compatibility in both x86 and x64 environments? I have scoured the Internet and I cannot seem to find a straight answer on how to handle this incompatibility.

I've also tried using an ODBC provider and a MSDASQL provider with no luck as they seem to throw the same exceptions as the Microsoft.JET.OLEDB.4.0 provider does when used in a x64 environment (unless I am doing something flagrantly wrong with these other two providers even though they work fine under in my Windows XP x86 environment).

I’ve found people saying that I need to use %WINDIR%\System32\odbcad32.exe for ODBC connectivity in x64 systems, but I have on idea how to utilize this.

Example Exeption Thrown Under x64:

************** Exception Text ************** System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)


回答1:


Everything that I've seen in my own recent research confirms what you are seeing - that there simply isn't a 64-bit Jet driver. Also, I found a post on THIS thread that seems to confirm that the 64-bit MSDASQL won't help as it is really just a wrapper (see the last post, dated May 8 from Ricky Wen). Your only option is to link thru a 32-bit proxy, perhaps another 32-bit SQL server. I may end up doing this myself, until I can move the Jet data to SQL.




回答2:


what's happening here is that a x64 assembly is trying to call a x86 COM component. The x64 app won't see the COM registrations in the primary x64 registry,since theyre in the wow6432node hive.

Easiest workaround is to build the application with a x86 target platform and let it run on the WOW later on your x64 machine. The app will run as 32-bit and be able to see the 32-bit COM objects it needs.




回答3:


There is now a 64 bit ODBC driver for JetSQL. It is the Microsoft Access Database Engine 2010 Redistributable. I have not used it for OLEDB, but I have used it to make new Microsoft Access databases with PowerShell.



来源:https://stackoverflow.com/questions/400684/querying-jet-databases-excel-files-with-c-sharp-under-x64-os

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!