OleDbException'未指定的错误'

时间:2013-05-17 17:57:04

标签: vb.net oledbexception

因此,只要下面的函数到达dataAdapter.SelectCommand = dbcommand行,我就会得到OleDBException“未指定的错误”。

我尝试添加dbcommand.connection.close()dbcommand.connection.dispose(),但都没有解决问题。

我假设每次尝试连接数据库时都会发生此错误,但这只是我的代码中第一个执行此操作的函数,因此这是错误首次发生的地方。

我在网上看到,MySQL最终会在一段时间后清除旧的连接,如果这是真的,那么我应该等待......但我不想等待一切都没发生。

    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

0 个答案:

没有答案