Replication and synchronization of network databases)

Source: Internet
Author: User

Database replica-Network Database Replication and synchronization (1)
Database Replicas are used to copy databases. Using this technology, several copies of the database can be synchronized. Each copy of a database is called a copy, and each copy contains a set of public tables, queries, forms, reports, macros, and modules; each copy can also contain local objects used only on the local computer.

In a multi-user environment, a database may be used by multiple users. In multi-user applications, database copies can improve the way users share databases. Using Database Replicas can re-generate a database so that two or more users can use their own Database Replicas at the same time. Although each copy is placed on a different computer, it is synchronized.

Database Replicas and their Topology

Two or more replicas of a database form a replica set, each of which is part of the replica set. The replica set contains several copies of the database and the original design master. The original design is the only copy that can be used to design and modify the database. Replicas in the same replica set can exchange data with each other and then copy objects for updates. This exchange is called synchronization.

1. Usage of Database Replicas

According to the traditional practice, in multi-user database applications, tables are usually separated from other objects in the database, so that data can reside on the network server, the query, form, report, Macro, and module reside on the user's computer. To retrieve or update information in the database, you must first log on to the network, then open the database on the computer, and then open the corresponding database on the server. If you use the database Copy technology, you can create a single database that contains both data and objects.

The database copy should be used in the following cases:

(1) data needs to be shared in various offices. You can use a database copy to create a copy of a Database Unit and send it to each relevant office. In each office, the user enters data into his/her own copy and synchronizes all remote copies with the copy of the Organization. The local table can be maintained at all levels of replicas. The table contains information from other replicas.

(2) data must be shared among scattered users. Each end user enters new information in the database outside the office, which can be synchronized at any time when the terminal establishes an electronic connection with the Organization's network. In daily work, end users can dial into the network to synchronize copies and use the latest version of the database. Since only new changes are transmitted during synchronization, the time and cost of data updates can be minimized. You can also use partia1 replicas to synchronize only part of the data.

(3) The availability of server data needs to be improved. If the application does not need to update data immediately, you can use the database to reduce network loading on the master server. When the second server is introduced by copying the database of the server itself, the response time can be improved.

(4) Update of the application to be released. When copying an application, not only the data in the table is automatically copied, but also the objects of the application. If you have made changes to the database design, the Microsoft Jet Database Engine will transmit these changes during the next synchronization without having to release a new version of the software.

(5) All data must be prevented from being lost. Database replica publishing spans data from multiple databases. Therefore, when the original database is damaged, you can use a database in the replica database to restore data.

Although Database Replicas can solve many problems inherent in Distributed Database processing, the replicas still do not meet the ideal requirements in the following situations:

1) You need to update a large number of records in multiple replicas. Applications that need to frequently update existing records in different copies may cause more conflict of records than applications that simply insert new records into the database. When users in different locations modify the same record at the same time, a record conflict occurs. The more application records conflict, the more processing time required, because these conflicts can only be solved manually.

2) strict requirements on data consistency. For transaction processing applications such as transfer of funds, booking of flight tickets, and tracking of parcel shipment, there must be no information error at ffnu. If you can process transactions in one replica, do not process the transactions in several replicas. During synchronization, the information exchanged between the replicas is the result of the transaction, not the transaction itself.

2. Replica Set Topology

The replica Set Topology determines the communication between each replica in the XT replica set and the tonp synchronization logic. The topology of a replica set can be in different forms. However, for most applications, there are two better topologies: A star structure and a fully connected structure ,.

 

Star full join

The star topology has a hub that regularly synchronizes with each satellite. In this topology, all data is shared among copies through a single centralized database. Because only two steps are required to synchronize data with other replicas, the star topology can reduce the waiting time of data in each replica.

During synchronization, if the average data size of the exchange is relatively small, the star topology may be the most effective solution for most applications. Its implementation is quite simple and effective and reliable. If this is the first implementation of the replica, it is best to use a star topology.

If you change each duplicate of the star topology to a hub, you can change it to a fully connected topology. In a fully connected topology, each replica is synchronized with all other replicas in the replica set. One of the most important advantages of a complete topology is that the data transmission has a low wait time. Because each duplicate is synchronized with all other replicas, data can be directly sent to all replicas without being indirectly transmitted through a series of duplicates.

Duplicate operation objects, attributes, and methods (1) -- replication and synchronization of network databases (2)
Objects, attributes, and methods related to the copy operation

To achieve replica dryness, the Microsoft Jet Database Engine provides multiple objects, attributes, and methods. This section describes the objects, attributes, and methods related to the copy operation.
1. Document Object and Documents Set
The document object contains information about an instance of an object. The object can be a database, table, query, or link (for Microsoft Jet Database only ).
Each container object has a collection of documents containing the Document Object (for details about its relationship, see the Help File of VB). These document objects describe instances of built-in objects of the type specified by the container. Table 1 lists the types of objects described in the document, their iner object names, and types of document information.

Information contained in document iner
Database database saved Database
Tables or query tables or query saved tables
Saved Link

(Table 1)

The document object can be used to perform the following operations:

· Use the name attribute to return the name given to the object when the user or Microsoft Jet Database Engine creates the object.
· Use the container property to return the name of the document iner object containing the document object.
· Use the owner attribute to set or return the owner of an object. To set the owner attribute, you must have the write permission on the document object and set the username attribute to the name of an existing user or group object.
· Use the username or permissions attribute to set or return the access permissions of a user or group object. To set these attributes, you must have the write permission on the document object and set the username attribute to the name of an existing user or group object.
· Use the datecreated attribute and the lasupdated attribute to return the date and time when the document object was created and last modified, respectively.

Because a Document Object corresponds to an existing object, you cannot create a new document object or delete an existing document object. A document collection contains multiple document objects. You can reference a document object in the following formats:

Documents (0)
Documents ("name ")
Documents! [Name]

2. container object and containers set

The contalner object puts document objects of similar types in a group. Each database object contains a containers set composed of internal iner objects. Applications can define their own document types and corresponding containers (only for Microsoft Jet databases), but these objects are not always supported by Dao. Some iner objects are defined by the Microsoft Jet Database Engine and can also be defined by other applications. The container object defined by the Microsoft Jet Database Engine and Its information are shown in table 2.

Information contained in the container object
Database
Table Storage and Query
Link saved

(Table 2)

Note:

1 .) each container object contains a collection of documents composed of document objects. Generally, the container object is used as a direct link to the information in the document object. You can also use the Container set to set security for a document object of a given type.

2) You can use the iner object to perform the following operations:

· Use the name attribute to return the predefined name of the container object.
· Use the permissions and username attributes to set the permissions of the container object. Create a document object in the documents set of the container object to inherit these access permission settings.
· Use the owner attribute to set or return the owner of the container object. To set the ower attribute, you must write the container object permission and set the attribute to the name of an existing user or group object.

(3) The container object is scheduled by the system. Therefore, you cannot create a new container object or delete an existing container object.

(4) You can set or reference the container object in the set through the sequence number or name attribute, for example:
Containers (0)
Containers ("name ")
Containers! [Name]

[Example] compile a program to list the documents set in the tables container.

Draw a command button on the form and write the following event process:

Private sub commandementclick ()
Dim dbsnorthwind as database
Dim docloop as document
Dim prploop as property
Set dbsnorthwind = opendatabase ("E: \ f. mdb ")
With dbsnorthwind. Containers! Tables
Debug. Print "Events in" &. Name & "Container"
Note: List the documents collections in the table container.
For each docloop in. Documents
Debug. Print "& docloop. Name
Next docloop
End
Dbsnorthwind. Close
End sub

This process lists the documents set in the table container of the f. mdb database. After the program runs, click the command button to list the set in the "now" window.

Duplicate operation objects, attributes, and methods (2)-Network Database Replication and synchronization (3)
3. Property object and properties set

The property object is used to describe the internal or user-defined attributes of a DaO object. The relationship with Dao object and properties set is that Dao object contains the properties set, and the properties set contains the property object. (For details about the relationship, see the VB help file)

Except for the connection and error objects, each DAO object contains a property set, in which there is a property object consistent with the internal properties of the corresponding Dao object. At the same time, you can define a property object and add it to the properties set of some of the following Dao objects:
· Database, index, querydef, and tabledef objects
· Field object in the fields set of the tabledef object and querydef object
Property has four predefined attributes:
· Name attribute: a string that uniquely identifies a property.
· Type attribute: it is an integer used to specify the Data Type of the attribute.
· Value Attribute: A value of the variant type that contains the attribute settings.
· Inherited property: A boolean value that indicates whether the property is inherited from another object.
A property object has both predefined attributes and user-defined attributes. Its format is different when being referenced. The reference format of the top-defined attribute is:
Object. Attribute
User-Defined attributes must use the following reference format:
Object. properties. ("attribute ")

[Example] compile a program to list the documents set in the tables container, and then list the properties set of the first document object in the set.

Draw a command button on the form and write the following event process:

Private sub commandementclick ()
Dim dbsnorthwind as database
Dim docloop as document
Dim prploop as property
Set dbsnorthwind = opendatabase ("E: \ f. mdb ")
With dbsnorthwind. Containers! Tables
Debug. Print "Events in" &. Name & "Container"
For each docloop in. Documents
Debug. Print "& docloop. Name
Next docloop
With. Documents (0)
Debug. Print "properties of" &. Name & "document"
On Error resume next
For each prploop in. Properties
Debug. Print "& prploop. Name &" = "& prploop
Next prploop
On Error goto 0
End
End
Dbsnorthwind. Close
End sub

The first half of the program is the same as the previous example. The second half lists the properties set of the first document object (that is, documents (0. Run the program and click the command button to list the above content in the "now" window.

User-Defined attributes are defined using the createproperty method. This method can be used to create a user-defined property object (only in the Microsoft Jet workspace) for database, document, field, index, querydef and tabledef objects. The format is:

Set property = object. createproperty (name, type, value, DDL)

The meanings of parameters are as follows:

· Property: object variable, the property object to be created.
· Object: object variables, which can be database, field, index, querydef, and tabledef objects. You can create property objects for these objects.
· Name: Optional. Variant Type (string subtype), uniquely named the new property object.
· Type: Optional. Constant to define the type of the new property object.
· Value: Optional. Variant type, which specifies the initial value of the attribute.
· DDL: Optional. Variant Type (Boolean subtype) is used to indicate whether the attribute is a DDL object. The default value is false. If DDL is true, the property object cannot be deleted (unless permitted by dbsecwritedef ).

Note:

1) only user-defined property objects can be created in the property set of a permanent object. When using the createproperty method to create a property object, if one or more optional parameters are omitted, you can add a new object to a set before, use the value assignment statement to set or reset the corresponding attributes. After appending a new object to the set, you can change some of its attribute settings (not all ).

2) if the name parameter refers to an existing object member in the Set, an error will occur when append is used.

3.) to delete a user-defined attribute object from a set, you can use the delete method of the set. This method can only delete user-defined objects and cannot delete predefined attributes.

4.) If the DDL parameter is omitted, the default value is false (that is, non-DDL ). In this case, there is no corresponding DDL attribute. If you need to change a property object from DDL to DDL, you must first Delete the object and then recreate it.

5.) The type parameter in the createproperty method is a symbolic constant, which is the set value or return value of the property object. The possible values are shown in table 3.

Value of the type parameter

Constant type constant type
Dbbigint big integer dbguid
Dbbinary binary dbinteger integer
Dbboolean Boolean dblong long integer
Dbbyte byte dblongbinary long binary (OEL object)
Dbchar character dbmemo memo
Dbcurrency currency dbnumeric Value
Dbdate date/time dbsingle single precision
Dbdecimal decimal dbtext
Dbdouble double precision dbtime
Dbfloat floating point dbtimestamp Timestamp
Dbvarbinary varbinary

(Table 3)

If mydb is a database object variable and mypro is a property object variable, you can use the following program to create a property object:

Set mypro = mydb. createproperty ()
Mypro. Name = "newdefined"
Mypro. type = dbtext
Mypro. value = "this is a user-defined attribute"

You can use the following statement to add a new property to the properties set:

Mydb. properties. append prpnew

[Example] compile a program, create a user-defined property object, and add it to the properties set. Draw a command button on the form and write the following event process.

Private sub commandementclick ()
Dim dbsnorthwind as database
Dim prpnew as property
Dim prploop as property
Set dbsnorthwind = opendatabase ("E: \ f. mdb ")
With dbsnorthwind

Note: Create and add user-defined attributes

Set prpnew =. createproperty ()
Prpnew. Name = "userdefinednew"
Prpnew. type = dbtext
Prpnew. value = "This Is A user_definednew property ."
. Properties. append prpnew

Note: List all attributes of the current database.

Debug. Print "properties of" &. Name
For each prploop in. Properties
With prploop
Debug. Print "& name
Debug. Print "type:" &. Type
Debug. Print "inherited:" &. inherited
End
Next prploop
End
End sub

The above program creates an attribute named userdefinednew, whose type is dbtext and the initial value is "This is a user_definednew property ." Run the program and click the button to create this attribute. All attributes of the current database are displayed in the displayed window. (Including new attributes)

 

/*************************************** ******************
Manually create databases, tables, and other SQL statements, and execute the corresponding statements in the program.

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.