>I am trying to connect to an Excel document in my ASP.NET 1.1 app. I am using the following connection string:
>
>
>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
>
>
>When I attempt to fill my dataset, it throws an error when the file is open. Is there a way to perform a read only connection where it doesn't matter if the file is open?
I have opened the Excel file. Then, I tried this code:
Dim loCommand As System.Data.OleDb.OleDbDataAdapter
Dim loConnection As System.Data.OleDb.OleDbConnection
Dim loDataSet As System.Data.DataSet
loConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + _
"data source=d:\Excel.xls;Extended Properties=Excel 8.0;")
loCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [excel$]", loConnection)
loCommand.TableMappings.Add("Table", "Attendence")
loDataSet = New System.Data.DataSet
loCommand.Fill(loDataSet)
MessageBox.Show(loDataSet.Tables("Attendence").Rows.Count)
loConnection.Close()
It works ok. Can you try this code and let me know?
Or, could it be that there could be default setting in Excel that forces the file to be exclusive?