Search code examples
c#exceloledb

Reading Excel Sheet with OleDb


I am trying to read an excel sheet through Microsoft.Jet.OLEDB.4.0. I followed a tutorial and write the code and deployed it. It was working fine but now after a long time we changed the server and now when I deployed the old code to the new server its giving me an error "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine."

I really dont remember what I did last time to make it running. I have tried alot of things but nothing worked.

I cant use any other dll because we dont have office installed on the server. Can any one please guide me.


Solution

  • The 'Microsoft.Jet.OLEDB.4.0' is a 32bit driver. If you compile your application with the AnyCPU as Platform target and deploy your application on a 64bit OS then your code is executed as 64bit code. In this context you are not able to reference a 32bit driver like OleDb.4.0.

    Your best option is to recompile your application for x86 as target Platform and then your application will run as 32bit code that will be run without problem on a 64bit system and you will be able to use the 32bit OleDb.4.0.

    If this is not possible then you should download the Microsoft Access Database Engine 2010 Redistributable in the 64bit version and install it on the target server. Also remember to change your connection string to

     string conString = "Provider=Microsoft.ACE.OLEDB.12.0;" + 
                        "Data Source=path_to_your_excel_file.xls;" + 
                        "Extended Properties=\"Excel 8.0;HDR=YES\"";