Microsoft.Jet.OleDb and x64 Machines

Nov 5, 2008

I started a new project today where I need to read data from an Excel spreadsheet. I’ve done this many times before by using the Microsoft.Jet.OleDb provider which allows me to write SQL statements to retrieve the data. Except this time around I am working on a x64 machine, and it turns out that Microsoft.Jet.OleDb doesn’t like playing with x64 operating systems.

I received the following error on my Vista x64 system when trying to connect to an Excel file through Microsoft.Jet.OleDb:

The ‘Microsoft.Jet.OLEDB.4.0′ provider is not registered on the local machine.

After searching the net for a while I found the solution. I needed to compile the application to use the x86 platform. By default the platform target is ‘AnyCPU’ which is the platform the current machine is on (in my case x64). So no problem, I just had to change the platform target, which is easy enough to do in Visual Studio Standard or Pro Editions. You go to Project -> Properties -> Build then choose the platform target from the combo box. Well, I have Visual C# Express, and the Express edition does not have this combo box. So I had to manually open the .csproj file for the application and add the <PlatformTarget> tags. Below is an example.

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

Make sure to set the <PlatformTarget> tag in both the Debug and Release areas.

And that is the fix to read Excel files from an x64 machine.

Posted by admin | Categories: Uncategorized |

Share with others

5 Responses so far | Have Your Say!

  1. GDJared
    November 5th, 2008 at 7:06 pm #

    Спасибо!

  2. ErvinTW
    November 11th, 2008 at 2:56 pm #

    Thanks! Nice post.

  3. RYErnest
    December 1st, 2008 at 3:40 am #

    Nice post u have here :D Added to my RSS reader

  4. .Net Ramblings » Blog Archive » Getting started with NHibernate and SQL Compact Edition
    December 8th, 2008 at 1:01 pm #

    [...] this post for more information on updating the .csproj [...]

  5. Andreas Kienle
    December 26th, 2009 at 11:15 am #

    Thanks! I spent hours searching for a solution.

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>