Discussion Locked

OledbException: Unrecoginzed Data Format

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm trying to display Dataset from Excel file to ASPX page. I'm using OLEBD connection to do so but when trying to run my code..it gives me following error

Exception Details: System.Data.OleDb.OleDbException: Unrecognized database format 'c:\inetpub\wwwroot\ExcelData.xls'.

Here is the code of my application
// Create connection string variable. Modify the Data Source"

OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../ExcelData.xls"));
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 myRange1", 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, "XLData");

DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();

// Clean up objects.
objConn.Close();

I appreciate your help.
Thanks.

1 reply

by ahar

Review your connectionstring!
First, don't use JET (oudated and slow)
make an ODBC-SystemDSN
and use a connectionstring like
Provider=MSDASQL.1;Persist Security Info=False;Data Source=excel_test;Initial Catalog=\

This discussion is closed to new replies.