0

我在我的办公室继承了一个 MS Access 数据库,该数据库被网络上的几个人大量使用。这会导致许多数据冲突和锁定问题。我想拆分数据库,以便每个用户都有自己的前端应用程序并在服务器上维护核心数据。

有几个表使用 autonumber:sequence:long 作为主键 - 在研究如何执行拆分时,我遇到了几篇文章,暗示这可能会在分发数据库时导致问题,但我找不到任何东西坚硬的。问题似乎是用户可以开始新记录并接收下一个自动编号,但第二个用户可以在短时间内创建新记录并接收相同的自动编号导致错误?

Jet 是否正确处理此问题,或者 FE/BE 数据库是否存在自动编号问题?如果这是一个不太可能但可能发生的情况,我相信它仍然会比我的用户目前所经历的要好得多,但我想知道是否有办法可以最大限度地减少此类问题。

谢谢你的帮助!

4

4 回答 4

2

我很不幸在年轻时使用过许多 Access 数据库。虽然 Access 存在许多问题,但我不知道我是否曾经在拆分数据库、多用户环境中遇到自动编号列的问题。它应该可以正常工作。这是一种常见的设置,如果出现问题,互联网上都会有关于它的帖子。

于 2011-01-05T04:13:07.123 回答
0

只要您不进行数据复制(即多个订阅者数据库,用户可以在相同的表中但在不同的位置插入新记录),您就不会遇到将自动编号作为主键的问题。

如果您认为其中一天可能需要进行复制(不同位置,一个中央数据库),请不要犹豫,切换到唯一标识符(复制 ID)。

于 2011-01-05T23:13:22.470 回答
0

您似乎对拆分过程有些困惑。当你这样做时,你最终会得到多个前端,但后端仍然是一个文件。因此,就自动编号而言,数据表与拆分应用程序之前的数据表没有任何区别。

于 2011-01-08T04:09:44.447 回答
0

我遇到了同样的问题,但是我做了一个解决方法来从Onload()事件中获取自动编号工作

我所做的是:

  1. 每次用户需要自动编号时,我都会根据 Your_Table 创建一个记录集
  2. 打开记录集(第一次)
  3. 搜索是否:
    -Your_Table 为空,然后将值“1”分配给 Your_field
    -Your_Table 包含没有缺失数字的数据,然后将值 =“行数 + 1”分配给 Your_field (1,2,...., n+1)
    -Your_Table 有缺失数据 (1,3,4,5,7) [注意“#2 和 #7 缺失]”,然后使用函数在 Your_Table 中搜索缺失的字段并将第一个分配给 Your_Field缺失值(本例中的#2)


Private Sub Autonumbering(Your_Table As String)
Dim rst As DAO.Recordset
Dim db As Database

On Error GoTo ErrorHandler

Application.Echo False

Set db = CurrentDb
Set rst = db.OpenRecordset(Your_Table, dbOpenDynaset)

                    With rst
                        .AddNew
                            'Your_Table is Empty, **then** assigns the value "1" to Your_field
                            If DMin("[Your_Field]", Your_Table) = 1 Then
                                'Your_Table is has data without missing numbers,**then** assigns the value = "Count of lines + 1" to Your_field (1,2,....,n+1)
                                If DMax("[Your_Field]", Your_Table) = .RecordCount Then
                                    'Assings n+1 value to [Your_Field] records
                                    Value = .RecordCount + 1
                                        ![Your_Field] = Valor
                                Else
                                    'Your_Table has missing data (1,3,4,5,7) [Note "#2 and #7 are missing]", **then** uses a function to search in Your_Table & _
                     the missing fields and assign to Your_Field the first missing value (#2 in this example)
                                    Value = MyFunction$(Your_Table, "Your_Field")
                                        ![Your_Field] = Value
                                End If
                            Else
                            'Agrega el número 1
                            Value = 1
                            ![Your_Field] = Value
                            End If
                        .Update
                        .Bookmark = .LastModified
                        Me.Requery
                        DoCmd.GoToRecord acDataForm, Me.Name, acGoTo, Value
                        .Move 0, .LastModified
                    End With
ErrorCorregido:
Application.Echo True
Exit Sub

ErrorHandler:
MsgBox "An error ocurred, please verify numbering", vbCritical + vbOKOnly
Resume ErrorCorregido

End Sub


这是我发现的在特定表上获取缺失值的函数,我再也找不到它了,但感谢制作它的人。


Function MyFunction$(cstrTable As String, cstrField As String)

' Read table/query sequentially to record all missing IDs.
' Fill a ListBox to display to found IDs.
' A reference to Microsoft DAO must be present.

  Dim dbs     As DAO.Database
  Dim rst     As DAO.Recordset
  Dim lst     As ListBox
  Dim Col     As Collection

  Dim strSQL  As String
  Dim strList As String
  Dim lngLast As Long
  Dim lngNext As Long
  Dim lngMiss As Long

  ' Build SQL string which sorts the ID field.
  strSQL = "Select " & cstrField & "" _
   & " From " & cstrTable & " Order By 1;"

  Set Col = Nothing
  ' Control to fill with missing numbers.
  'Set lst = Me!lstMissing

  ' Collection to hold the missing IDs.
  Set Col = New Collection

  '// Vacía la colección
  'Erase Col
    ' Read the table.
  Set dbs = CurrentDb
  Set rst = dbs.OpenRecordset(strSQL)

  If rst.RecordCount = 0 Then
    ' The recordset is empty.
    ' Nothing to do.
  Else
    ' Read and save the ID of the first record.
    lngLast = rst(cstrField).value
    rst.MoveNext
    ' Loop from the second record through the recordset
    ' while reading each ID.
    While rst.EOF = False
      lngNext = rst(cstrField).value
      ' For each ID, fill the collection with the
      ' missing IDs between the last ID and this ID.
      For lngMiss = lngLast + 1 To lngNext - 1
        Col.Add (lngMiss)
      Next
      ' Save the last read ID and move on.
      lngLast = lngNext
      rst.MoveNext
    Wend
    ' Finally, add the next possible ID to use.
    Col.Add (lngLast + 1)
  End If
  rst.Close

  For lngMiss = 1 To Col.Count
    ' Build the value list for the ListBox.
    If Len(strList) > 0 Then
      ' Append separator.
      strList = strList & ";"
    End If
    ' Append next item from the collection.
    strList = strList & Col(lngMiss)
    ' For debugging only. May be removed.
    Debug.Print Col(lngMiss)
  Next
  ' Pass the value list to the ListBox.
  ' Doing so will requery it too.
  ' lst.RowSource = strList
  ' For debugging only. May be removed.
  ' Debug.Print strList
  MyFunction$ = Col(1)
  ' Clean up.
  Set rst = Nothing
  Set dbs = Nothing
  Set Col = Nothing
  Set lst = Nothing

End Function
于 2015-10-27T19:55:29.567 回答