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

Posted

技术标签:

【中文标题】OleDb 异常 System.Data.OleDb.OleDbException (0x80004005): 超出系统资源【英文标题】:OleDb exception System.Data.OleDb.OleDbException (0x80004005): System resource exceeded 【发布时间】:2019-05-20 15:13:07 【问题描述】:

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 行超出系统资源。我只是不确定为什么会超出资源以及我需要做些什么来避免这种异常。好像我建立了一个连接,然后用它来进行许多查询。应该可以正常工作吗?

【问题讨论】:

Seems like I make one connection and then use it to make many queries不要这样做。在需要时使用它们,并在完成后丢弃它们。恕我直言,请查看Using 语句和参数...另外,您正在填写DataSet,但只使用一个表,不要那样做,只需Fill 一个DataTable... Çöđěxěŕ 所说的以及创建 sCodes 的更简洁的方法是 Dim sCodes As String = String.Join(", ", sysCodes.Select(Function(s) "'" &amp; s &amp; "'")) 【参考方案1】:

感谢 Çöđěxěŕ 和 Andrew Morton。不要记得我从哪里得到代码 sn-p 但已经使用了多年。我想不同之处在于这次我在大量呼叫中使用该例程。这是我测试过的更新代码,没有例外:

        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

【讨论】:

以上是关于OleDb 异常 System.Data.OleDb.OleDbException (0x80004005): 超出系统资源的主要内容,如果未能解决你的问题,请参考以下文章

OLEDB - C++ - ATL 的 OLEDB 提供程序示例使 Excel 崩溃(来自 msado15.dll 的未捕获异常)

OleDB 异常:找不到可安装的 ISAM

OLEDB 参数插入的奇怪异常

OLEDB 连接抛出异常“参数太少”

Oledb 异常未处理。操作必须使用可更新的查询

使用 Oledb 对象插入 ms-access 查询获取无效查询异常