Access 2010在单用户数据库中给出了锁定错误-2147217887(80040e21)

时间:2019-01-16 14:26:35

标签: locking runtime-error ms-access-2010

我有一个Access 2010数据库,可用来扫描硬盘驱动器以检测文件的多个版本。 基本上,我有一个包含文件的表,在该表上定义了一个记录集“ filesTable”:

Private filesTable As ADODB.Recordset
Private foldersTable As ADODB.Recordset

Sub initFilesTable()
    CurrentProject.Connection.Execute "DELETE ALL * FROM files", , adCmdText
    Set filesTable = New ADODB.Recordset
    filesTable.Open "SELECT files.[folderName], " & _
    " files.[fileName], " & _
    " files.[fileSize], " & _
    " files.[dateModified] " & _
    " FROM files;", _
    CurrentProject.BaseConnectionString, adOpenForwardOnly, _
    adLockPessimistic, adCmdText
End Sub

和带有文件夹的表,记录集为“ foldersTable”:

Sub initFoldersTable()
    CurrentProject.Connection.Execute "DELETE ALL * FROM folders1", , adCmdText
    Set foldersTable = New ADODB.Recordset
    foldersTable.Open "SELECT folders1.[folderName], " & _
    " folders1.[folderCount], " & _
    " folders1.[fileCount], " & _
    " folders1.[fullPath], " & _
    " folders1.[size] " & _
    " FROM folders1;", _
    CurrentProject.BaseConnectionString, adOpenForwardOnly, _
    adLockPessimistic, adCmdText
End Sub

最初,我记录了每个文件:

Sub addFileToTable(folder As folder, file As file)
With filesTable
    .AddNew
    !folderName = folder.path & "\"
    !fileName = file.Name
    !FileSize = file.Size
    !DateModified = file.DateLastModified
    .Update
End With
End Sub

,它工作正常。该子例程在文件夹上是递归的。我可以将十万个文件读到表中。

然后我添加了文件夹的记录,这与文件的记录同时完成:

Sub addFolderToTable(folder As folder, folderFileCount As Long)
    With foldersTable
    .AddNew
    !folderName = folder.Name
    !FolderCount = folder.SubFolders.Count
    !FileCount = folderFileCount
    !FullPath = folder.path
    !Size = folder.Size
    .Update
    End With
End Sub

然后数据库开始出现错误:

运行时错误'-2147217887(80040e21)' 无法更新;此元素当前已锁定 (消息的措词不正确)

在addFileToTable或addFolderToTable子句中使用.update命令的行中。

它不在特定的文件记录中。系统可以读取包含数百个文件的文件夹,并且不会产生任何错误。但是,当我选择包含数千个文件的文件夹时,出现错误。如果我注释行以更新文件夹,则不会出现任何错误,因此问题似乎是同时对两个表进行更新(当对表进行了许多更新时)。我在recordSet.open命令中尝试了lockType和cursorType的几种组合,没有任何变化。有时,在使用同一起始文件夹的情况下,失败的文件数为1万,有时失败的文件数为5000。

有什么办法可以做?

0 个答案:

没有答案