Question

I am changing my application from Windows Forms to a Windows Service.

conn.GetSchema("Tables") is working differently in the two code bases.

In the new code base, I cannot get the Excel worksheets returned. conn.GetSchema("Tables").Rows.Count is 0. I have double checked all of the references and nothing is different. I can't find any other differences in my code that I can think would have this effect. Any ideas and what else I can look for?

Here is my full function (yeah, I know I should be using a For Each):

Private Function GetWorksheets(FileName As String) As String()

    Dim rv As List(Of String)
    Dim conn = New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" & FileName & ";Extended Properties=Excel 8.0;")

    conn.Open()
    For x As Integer = 0 To conn.GetSchema("Tables").Rows.Count - 1
        rv.Add(conn.GetSchema("Tables").Rows(x)("TABLE_NAME"))
    Next x
    conn.Close()
    Return rv.ToArray

End Function

Thanks, Brad

Was it helpful?

Solution

You need to include the path of web server (System.Web.HttpContext.Current.Server.MapPath), so try replacing the "conn" assignment with the following:

Dim conn = New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" &  System.Web.HttpContext.Current.Server.MapPath(FileName) & ";Extended Properties=Excel 8.0;")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top