I have the following code :
string excelConnectionString = @\"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\db\\suc.xls; Extended Properties=\"\"Excel 1
I had the same kind of problem. I was using an Excel 2010 database. But I had a xlsx file instead of xls. I solved my problem using the connection string as fallows,
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=logbook.xlsx;Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';
What I was missing are, I used OLEDB.4.0 instead of ACE.12.0 . I tried using ACE.14.0. But it didn't work either. Then I missed inverted commas ( ' ' ) around Extended Properties.
Sorry if the answer is hard to read, I am uploading this in my phone.
I had the same error, but none of the suggestions above worked. In my case all I had to do was to change my connection string to this:
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties='Excel 12.0;IMEX=1;'";
Note the Single Quote around the Extended Properties attribute ('Excel 12.0;IMEX=1;'). Once I added those single quotes the error disappeared!
There's no 64 bit version of the Jet OLEDB drivers, so if you are running this on a 64 bit OS you might need to target x86
in your .NET application and not Any CPU
:
On 64-bit Windows and 64-bit Office (2010, 2013) environments, there are many reports on this error. The fix or workaround is a bit strange but seems to work for most people out there.
The "Microsoft Access Database Engine 2010 Redistributable" installation package seems the natural one to use but several reports says it does not work.
Instead, using the "2007 Office System Driver: Data Connectivity Components" seems to solve the above problem for most people.
// SET A CONNECTION WITH THE EXCEL FILE.
OleDbConnection myExcelConn = new OleDbConnection
("Provider=Microsoft.ACE.OLEDB.12.0; " +
"Data Source=" + Server.MapPath(".") + "\\" + fileUpload1.FileName +
";Extended Properties='Excel 12.0;HDR=YES'");
Putting Single quote in Extended Properties like Extended Properties ='Excel 12.0:HDR=YES' solved my problem.
I was getting this issue trying to opening an xls file with a more recent provider. I fixed this issue by changing my extended properties from
Extended Properties="Excel 11.0;"
to
Extended Properties="Excel 8.0;"
I guess Excel 11 expects an xlsx style file.