Search code examples
c#.netdatabase-connectionoledbexport-to-excel

Error connecting to excel


I need to programmatically read Microsoft Excel file from a specific path. The following code results in an error message I have never seen before

string sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath("Book1.xls") + ";" + "Extended Properties=Excel 12.0 Xml;HDR=Yes"; 
        OleDbConnection con = new OleDbConnection(sConnectionString);
        con.Open();

While opening the connection, the following error message is shown:

Could not find installable ISAM.

Does anybody have a solution related to this error? I would appreciate your help in this.


Solution

  • According to this question, you have to enclose the properties in quotes and make sure the path doesn't contain spaces.

    Change your code to

    string sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath("Book1.xls") + ";" + "Extended Properties='Excel 12.0 Xml;HDR=Yes'";