繁体   English   中英

MS Access 并发用户

[英]MS Access concurrent users

我只是有一个关于 MS Access Concurrency 的快速问题。 我在 excel 中构建了一个输入表,VB 代码在大约 5 毫秒内打开与 MS Access 数据库的连接,记录 8 个字段并立即关闭连接(对于该特定用户)。 我意识到 Access 在并发方面有其局限性,但我真的想知道这对于 70 个用户是否合适? 并非所有人都会在完全相同的时间记录数据,如果发生这种情况,我想说 70 个(最多)中的 20-30 个可能会在完全相同的时间记录某些内容。

另一方面,Access 数据库仅用于存储数据,仅用于存储数据。

    Dim NewCon As ADODB.Connection
    Set NewCon = New ADODB.Connection
    Dim Recordset As ADODB.Recordset
    Set Recordset = New ADODB.Recordset

    NewCon.Open "Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\my.user\Desktop\Testing\Database1.accdb"
    Recordset.Open "DATA", NewCon, adOpenDynamic, adLockOptimistic
    Recordset.AddNew
    'Primary Key
    Recordset.Fields(0).Value = G
    'Field 2
    Recordset.Fields(1).Value = A
    'Field 3
    Recordset.Fields(2).Value = B
    'Field 4
    Recordset.Fields(3).Value = C
    'Field 5
    Recordset.Fields(4).Value = D
    'Field 6
    Recordset.Fields(5).Value = E
    'Field 7
    Recordset.Fields(6).Value = F
    'Field 8
    Recordset.Fields(7).Value = Format(Now, "m/d/yyyy h:mm:ss")


    Recordset.Update
    Recordset.Close
    NewCon.Close

这应该不是问题。 或者捕获错误并重试。

如果遇到严重问题,可以使用此处描述的方法:

静默处理 Access 中的并发更新冲突

其中包括完整的演示和代码:

' Function to replace the Edit method of a DAO.Recordset.
' To be used followed by GetUpdate to automatically handle
' concurrent updates.
'
' 2016-02-06. Gustav Brock, Cactus Data ApS, CPH.
'
Public Sub SetEdit(ByRef rs As DAO.Recordset)

    On Error GoTo Err_SetEdit

    ' Attempt to set rs into edit mode.
    Do While rs.EditMode <> dbEditInProgress
        rs.Edit
        If rs.EditMode = dbEditInProgress Then
            ' rs is ready for edit.
            Exit Do
        End If
    Loop

Exit_SetEdit:
    Exit Sub

Err_SetEdit:
    If DebugMode Then Debug.Print "    Edit", Timer, Err.Description
    If Err.Number = 3197 Then
        ' Concurrent edit.
        ' Continue in the loop.
        ' Will normally happen ONCE only for each call of SetEdit.
        Resume Next
    Else
        ' Other error, like deleted record.
        ' Pass error handling to the calling procedure.
        Resume Exit_SetEdit
    End If

End Sub

和:

' Function to replace the Update method of a DAO.Recordset.
' To be used following SetEdit to automatically handle
' concurrent updates.
'
' 2016-01-31. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function GetUpdate(ByRef rs As DAO.Recordset) As Boolean

    On Error GoTo Err_GetUpdate

    ' Attempt to update rs and terminate edit mode.
    rs.Update

    GetUpdate = True

Exit_GetUpdate:
    Exit Function

Err_GetUpdate:
    If DebugMode Then Debug.Print "    Update", Timer, Err.Description
    ' Update failed.
    ' Cancel and return False.
    rs.CancelUpdate
    Resume Exit_GetUpdate

End Function

同样在GitHub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM