OleDb异常System.Data.OleDb.OleDbException(0x80004005):超出系统资源

时间:2019-05-20 15:13:08

标签: sql vb.net exception resources oledb

VB2013:我收到异常System.Data.OleDb.OleDbException(0x80004005):超出了系统资源。当我查询MS Access数据库时。

这是我在代码中所做的:

'Make the connection to connDB
Public connDB As OleDbConnection
connDB = New OleDbConnection
With connDB
     .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DbFile & ";Persist Security Info=True;Jet OLEDB:Database Password=xxxxxx;"
     .Open()
 End With

 'iterate through some 2500 obects. each object has a set of codes and we will get their description here
  GetSysDefinitions (list of codes for an object)

'Close the connection to connDB;

Public Function GetSysDefinitions(sysCodes As List(Of String)) As String
    Try
        'check to see if the db is available
        If connDB Is Nothing Then Return ""

        'set up the SQL to get the System Codes and Definitions
        Dim sCodes As String = "'" & String.Join("', '", sysCodes) & "'"
        Dim sql As String = "SELECT * " & _
                            "FROM SYS_Codes " & _
                            "WHERE CODE IN(" & sCodes & ") ; "
        Dim daLs As New OleDbDataAdapter(sql, connDB)
        Dim dsLs As New DataSet
        Dim dtLs As New DataTable
        daLs.SelectCommand.CommandTimeout = 60 '60 seconds for the command to timeout
        daLs.Fill(dsLs, "Sys")  '<=== Exception here at some point
        dtLs = dsLs.Tables(0)

        'do something with records returned
    Catch ex As Exception
        Debug.Print(ex.ToString)
    End Try
End Function

这一切都很好。但是在某些时候,我得到了异常System.Data.OleDb.OleDbException(0x80004005):在daLs.Fill行超出了系统资源。我只是不确定为什么会超出资源,我需要做些什么来避免这种异常。好像我建立了一个连接,然后用它进行许多查询。应该工作正常吗?

1 个答案:

答案 0 :(得分:0)

感谢Çöđěxěŕ和Andrew Morton。不要忘记我在哪里获得了代码片段,但是已经使用了多年了。我想这次的区别是Im在大量调用中使用了该例程。这是我测试过的更新代码,没有例外:

        Using daLs As New OleDbDataAdapter(sql, connDb)
            Using dtLs As New DataTable
                'fill in the DataTable
                daLs.Fill(dtLs)
                dtLs.TableName = "CoreSys"

                'check for how many rows were returned
                'parse out rows
            End Using
        End Using