MS Access并发用户

时间:2017-11-16 17:43:47

标签: excel-vba access-vba ms-access-2016 vba excel

我对MS Access Concurrency有一个简单的问题。我在excel中构建了一个输入表,VB代码打开了与MS Access数据库的连接,在大约5毫秒内记录了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

1 个答案:

答案 0 :(得分:1)

这应该不是问题。或者发现错误并再试一次。

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

Handle concurrent update conflicts in Access silently

包括完整的演示和代码:

' 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