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))
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
var TranArr = new string[999, 20];
using (OleDbDataReader dr = command.ExecuteReader())
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.
Has any one come across this before and more importantly does anyone have a fix ?