0

So, i get the OleDBException "unspecified error" whenever the function below hits the dataAdapter.SelectCommand = dbcommand line.

I have tried adding dbcommand.connection.close() and dbcommand.connection.dispose() but neither fixed the problem.

I assume that this error would happen every time i try to connect with the DB but this is just the first function that does so in my code, so this is where the error is first occuring.

I have read online that MySQL will eventually clear out old connections after a while, if this is true, then i should just have to wait..but i dont want to keep waiting for nothing to happen.

    Function GetOrders(ByVal _numberrecords As Long) As DataTable
    Dim TaxConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
    Dim dbConnection As OleDbConnection = New OleDbConnection(TaxConnStr)
    Try
        'Code to get orders in call status. Sort oldest to newest
        ' dbConnection.Open()
        Dim queryString As String
        queryString = "SELECT TOP " & _numberrecords & " Orders.Control_Number, Orders.State, Orders.County, Orders.Status, Orders.ZipCode, Orders.OrderNumber, Orders.Client, Orders.Department "
        queryString += "FROM Orders "
        queryString += "WHERE(((Orders.Status) = 'Tax Cert Call' Or (Orders.Status) = 'Online')) "
        queryString += "ORDER BY Orders.Date_Received;"
        Dim dbCommand As OleDbCommand = New OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection
        'dbCommand.Connection.Close()
        'dbCommand.Connection.Dispose()
        'dbCommand.Dispose()
        Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter
        dataAdapter.SelectCommand = dbCommand
        Dim dataSet As DataSet = New DataSet
        dataAdapter.Fill(dataSet)
        If dataSet.Tables(0).Rows.Count >= 1 Then
            GetOrders = dataSet.Tables(0)
        End If

    Catch ex As Exception
        Console.WriteLine(ex.Message)
        myLogger.Log(ex.Message)
    Finally
        dbConnection.Close()

        dbConnection.Dispose()
    End Try


End Function
MaylorTaylor
  • 4,671
  • 16
  • 47
  • 76
  • What is the value of _numberrecords? And, you talk about MySql, but are you using MS-Access? – Steve May 17 '13 at 18:08
  • _numberRecords = 1 & yea, we are using MS Access, my bad. – MaylorTaylor May 17 '13 at 18:12
  • Have you tried to execute the same query with the Access interface? – Steve May 17 '13 at 18:13
  • Yep, that works just fine. I also did "Compact & Repair" on the DB and that didn't fix anything. It's such a vague error - makes it hard to debug. – MaylorTaylor May 17 '13 at 18:16
  • Can't find anything wrong. Just in case you have no record the function doesn't return anything, but this is not the problem. As a last thing, I will try to open explicitly the connection before assigning the object to the command. Also, if you like, you could post a sample database online so we could try your code. – Steve May 17 '13 at 19:04

0 Answers0