Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp me find the leak in this excel import code
    primarykey
    data
    text
    <p>The following method of course works, but after a certain number of uploads (this is not constant) my client gets the dreaded error: "System.Data.OleDb.OleDbException: Unspecified error"</p> <p><strong>Steps:</strong></p> <ol> <li>Client uploads an excel file via a File upload control</li> <li>File is saved to the file system</li> <li>File is opened via the oledb provider and read into a dataset</li> </ol> <p>My only guess is that the provider is somehow not releasing resources.</p> <p>The only way to clear this up (temporarily) is to reset IIS. For that reason, I'm inclined to think that the provider can get locked up by other websites on this server. We do host one site for a client (we did not build) that makes use of this provider, so it's possible that there is an issue on their end. Can anyone comment on this?</p> <p>Please take a look at the method below and help me get rid of this problem!</p> <pre><code>Public Shared Function GetExcelData(ByVal excelFile As String, ByVal sheetNumber As Integer) As DataSet Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;", excelFile) Dim excelDataSet As New DataSet() Using conn As New OleDbConnection(connString) conn.Open() Using dt As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) Dim excelSheets(dt.Rows.Count) As String Dim i As Integer = 0 For Each row As DataRow In dt.Rows excelSheets(i) = row("TABLE_NAME").ToString i += 1 If i = sheetNumber Then Exit For End If Next Using excelCommand As New OleDbCommand("Select * from [" &amp; excelSheets(sheetNumber - 1) &amp; "]", conn) Using excelAdapter As OleDbDataAdapter = New OleDbDataAdapter(excelCommand) excelAdapter.Fill(excelDataSet) End Using End Using End Using conn.Close() End Using Return excelDataSet End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload