Link to home
Start Free TrialLog in
Avatar of melli111
melli111Flag for United States of America

asked on

Could not find installable ISAM.

I receive the error message "Could not find installable ISAM." When I try to open an Excel file in my C# code behind of an aspx page. The code is:

// Create connection string variable. Modify the "Data Source"
        // parameter as appropriate for your environment.
        String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + Server.MapPath("template.xlsx") + ";" +
            "Extended Properties=Excel 8.0;HDR=NO;IMEX=1";

        // Create connection object by using the preceding connection string.
        OleDbConnection objConn = new OleDbConnection(sConnectionString);

        // Open connection with the database.
        objConn.Open();

        // The code to follow uses a SQL SELECT command to display the data from the worksheet.

        // Create new OleDbCommand to return data from worksheet.
        OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM Sheet1", objConn);

        // Create new OleDbDataAdapter that is used to build a DataSet
        // based on the preceding SQL SELECT statement.
        OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

        // Pass the Select command to the adapter.
        objAdapter1.SelectCommand = objCmdSelect;

        // Create new DataSet to hold information from the worksheet.
        DataSet objDataset1 = new DataSet();

        // Fill the DataSet with the information from the worksheet.
        objAdapter1.Fill(objDataset1, "ExcelData");

        // Bind data to DataGrid control.
        GridView2.DataSource = objDataset1.Tables[0].DefaultView;
        GridView2.DataBind();

        // Clean up objects.
        objConn.Close();
Avatar of PJBX
PJBX
Flag of United States of America image

I think you should have apostrophes around the Extended Properties value. For example:

Change:
  "Extended Properties=Excel 8.0;HDR=NO;IMEX=1";
To:
  "Extended Properties='Excel 8.0;HDR=NO;IMEX=1'";
Avatar of melli111

ASKER

After completing this step, I received a different error.  This error is "External table is not in the expected format. "  I assume this means that the program thinks that the Excel table is not in the correct format, but I am positive that this table is a normal Excel 2007 file
Oh. The template.xlsx in your connection string. You need to use another provider.

For 2007
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\TestWorkbook.xlsx;Extended Properties="Excel 12.0;HDR=YES;"

Also see:
http://www.connectionstrings.com/excel-2007
Thank you.  The error is now pointing to the line "objAdapter1.Fill(objDataset1, "ExcelData");" Saying that "The Microsoft Office Access database engine could not find the object 'Sheet1'.  Make sure the object exists and that you spell its name and the path name correctly. "
Confirm the Sheet Names in your wookbook.
Confirm the path (Server.MapPath("template.xlsx") ) is correct
I am 100% positive that the name in the Workbook is Sheet1.  The path could be causing the error.  I have the Excel file right in the same folder as the solution in Visual Studio.  When I try to move the Excel file to a folder like the C:\ drive, I receive an error that the path is not a valid Virtual path.
ASKER CERTIFIED SOLUTION
Avatar of PJBX
PJBX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I received a new error message when the follong line of code executes "objConn.Open();".  the error message reads

The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.