Keep the Access database synchronized

Source: Internet
Author: User
Tags exit constant integer mdb database access database

Synchronization (synchronization) is an important concept to be involved in the application of database in network environment. The basic process is roughly divided into the following steps: First, make a database to be a replica of the properties of the original design (called the original design in VB, Access is called the Design Master), and then according to the implementation of the application needs to copy from the original design of multiple copies (VB said copy), These replicas form a collection of replicas (the original design is also considered to be the first the initial copy), and then enable synchronization when the data or structure of any of the replicas in the set is changed to send the change and apply it to other members in this replica set, making the members of the copy set consistent in data or structure. The process of implementing synchronization is called Synchronization. VB6.0 for the realization of synchronization, in the database object to provide a number of properties and methods to achieve this process, the following introduction of several major attributes and methods, respectively, corresponding to the synchronization of several steps:

1. Replicable properties:

The Replicable property is used to make a replica of a database object or a Table object in a database, a query object, and so on, and becomes the original design. However, the database object does not provide the Replicable property, so you first create it with the Createpropety method, add it to the object's attribute set, and then assign it to the original design. For database objects, setting the Replicable property to "T" will make the database object replicable. The following code will make the Nwind.mdb database that comes with the VB6.0 installation directory a design original (to back up this library file before the operation to ensure security recommendations):

Private Sub Command1_Click()
   Dim dbNwind As Database
   '如果末引用DAO则一定要先引用
   Dim prpNew As Property
   Set dbNwind = OpenDatabase("Nwind.mdb", True)
   With dbNwind
   '建立Replicable属性,如果已经存在该属性则程序略过这一步
   On Error Resume Next
   Set prpNew = .CreateProperty("Replicable", dbText, "T")
   .Properties.Append prpNew
   '设置数据库的Replicable属性为True
   .Properties("Replicable") = "T"
   .Close
   End With
   End Sub

2. MakeReplica Method:

The MakeReplica method copies a new full copy from the original design. Its syntax is: database. MakeReplica replica, description, options, where replica is a string representing a new replica path name; Description is a descriptive string of the new replica being created; options are an option, Can be a dbRepMakePartial constant (creating a partial replica) or a Dbrepmakereadonly constant (prevents the user from modifying the Replicable object in the new replica), and if you want to create a partial copy that is read-only, add the parameter constant Dbrepmakereadonly + dbrepmakepartial.

In the first example, add code before closing the database:. MakeReplica "Nwreplica", "Replica of Nwind.mdb", copies a copy named Nwind.mdb from the original Nwreplica.mdb design, located in the same directory as Nwind.mdb. The following is a function that can be called flexibly in practical applications by passing parameters, each time a function is invoked to create a new copy:

Function MakeAdditionalReplica(strReplicableDB As String, strNewReplica As String, intOptions As Integer) As Integer
  Dim dbsTemp As Database
  On Error GoTo ErrorHandler
  Set dbsTemp = OpenDatabase(strReplicableDB)
  ' 如果在调用此函数时,intOptions处末给出参数, 则忽略该参数项,
   '默认建立一个完全的、可读/写的副本,否则就利用提供的参数按要求建立副本
  If intOptions = 0 Then
  dbsTemp.MakeReplica strNewReplica, "Replica of " & strReplicableDB
  Else
  dbsTemp.MakeReplica strNewReplica, "Replica of " & strReplicableDB, intOptions
  End If
  dbsTemp.Close
  ErrorHandler:
  Select Case Err
  Case 0:
  MakeAdditionalReplica = 0
  Exit Function
  Case Else:
  MsgBox "Error " & Err & " : " & Error
  MakeAdditionalReplica = Err
  Exit Function
  End Select
  End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.