Reading from Excel: Microsoft.Jet.OLEDB.4.0 error on 64 bit systems

时间秒杀一切 提交于 2019-12-04 12:13:49

问题


I am reading the contents of an excel sheet in my application using:

 OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0");
 _myDataSet = new DataSet();
 OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + "My Sheet" + "$]", con);

myCommand.Fill(_myDataSet);
con.Close();

This is failing in 64 bit systems with the error:

Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

How to make this work in 64 bit machines?


回答1:


Microsoft.Jet.OLEDB doesn't have 64bit version, only 32bit. Compile your application as 32bit (Platform target: x86 in build option).




回答2:


Microsoft released a driver distribution with a 64-bit driver that works for Access and Excel. You can download both the 64-bit and 32-bit versions from the MS downloads site. The download page also has a brief outline of what you would need to change in your connection string to reference the ACE driver.

In a nutshell, you install the 64-bit driver distribution and then change your connection string to something along the lines of:

string connStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=""Excel 8.0;IMEX=1""";



回答3:


I don't believe it works... see this related question: OleDB not supported in 64bit mode?

The problem seems to be that the COM/Interop is not designed for 64 bit environments, and so it can't be registered in 64 bit mode.

You can force your .NET app to run in 32 bit mode on the 64 bit machine, which will allow you to access the OleDB functionality.




回答4:


Forget it, use these dll from codeplex that solve this problem. http://exceldatareader.codeplex.com/



来源:https://stackoverflow.com/questions/3672523/reading-from-excel-microsoft-jet-oledb-4-0-error-on-64-bit-systems

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