views:

44

answers:

2

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?

A: 

I don't believe it works... see this related question: http://stackoverflow.com/questions/861022/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.

John Weldon
+2  A: 

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

Tomas Voracek
Yes, or you can use corflags.exe to switch the assembly to run in 32bit mode.
John Weldon