Hello,
I am using Visual studio 2013 on Windows 7 64-bit with Office 2007 32-bit.
I have a c# WCF service library project which is trying to read data from an excel file as follows:
string con = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=c:\temp\Book2.xlsx;" +
@"Extended Properties='Excel 8.0;HDR=Yes; IMEX=1;'";
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
var TranArr = new string[999, 20];
using (OleDbDataReader dr = command.ExecuteReader())
{ etc...
This results in an error "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."
When I copy the same code into a c# console application it works fine. I am running Windows 7 64-bit and 32-bit Office 2007 excel. In the Build properties the platform is set to "Any CPU". In the WCF project the 32-bit preferred is unchecked and greyed out but in the Console application it is ticked. I have tried downloading Microsoft Access Database Engine 2010 Redistributable , but this has not helped.
If I change the Platform target to X86 then I get the following runtime error:
WcfSvcHost encountered a critical error and must exit. This may be caused by invalid configuration file. Please inspect additional information below for detail.
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\User\documents\visual studio 2013\Projects\DCRules2\DCRules2\bin\Debug\DCRules2.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Has any one come across this before and more importantly does anyone have a fix ?
regards
Pat