簡體   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