Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connecting to open Excel document
Message
From
21/12/2006 02:24:28
 
 
To
18/12/2006 12:40:04
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
ASP.NET
Miscellaneous
Thread ID:
01178614
Message ID:
01179451
Views:
13
This message has been marked as the solution to the initial question of the thread.
>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?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform