简体   繁体   English

MS Access 并发用户

[英]MS Access concurrent users

I just have a quick question on MS Access Concurrency.我只是有一个关于 MS Access Concurrency 的快速问题。 I have built an input sheet in excel and the VB code opens a connection to a MS Access database logs 8 fields in about 5 milliseconds and closes the connection right away (for that particular user).我在 excel 中构建了一个输入表,VB 代码在大约 5 毫秒内打开与 MS Access 数据库的连接,记录 8 个字段并立即关闭连接(对于该特定用户)。 I realize that Access has its limitations with concurrency, but what I really want to know if this is okay for 70 users?我意识到 Access 在并发方面有其局限性,但我真的想知道这对于 70 个用户是否合适? Not all of them will be logging data at the exact same time, if that would happen, I would say like 20-30 out of the 70 (the most) might log something at the exact same time.并非所有人都会在完全相同的时间记录数据,如果发生这种情况,我想说 70 个(最多)中的 20-30 个可能会在完全相同的时间记录某些内容。

On another note, the Access Database is only used for storing data, nothing else.另一方面,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

It should not be an issue.这应该不是问题。 Or catch an error and try again.或者捕获错误并重试。

If you experience serious trouble, you can use the method described here:如果遇到严重问题,可以使用此处描述的方法:

Handle concurrent update conflicts in Access silently 静默处理 Access 中的并发更新冲突

which includes a full demo and code:其中包括完整的演示和代码:

' 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

and:和:

' 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

Also at GitHub同样在GitHub

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

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