SQL SERVER (2005/2008) database synchronization replication tutorial

I look at the original space: http://user.qzone.qq.com/361367651/blog/1372927361 
SQL Server 2005, although there is a considerable increase, when its replication synchronization feature set of parameters will be slightly inaccurate synchronization failed. Here we actually had a successful test case for illustration, describe in detail how the publication and subscription databases.
Case Description: 

conventional two servers A and B are configured as follows:

[IMG = HTTP:?! //B163.photo.store.qq.com/psb / V11xFz8r3UOa3G / 2Xl24XcWiZq1ooPrsZb5g3KfCqMP6YEuU * KtsqCvPa0 / B / BO = & dEZoLGG7FwAA zAGlAAAAAAABAE8!] [ / img]
 

FIG
case requires: B as a backup server, the timing from the database server A copied data synchronization PubTest day. Maintaining exactly the same data.
Here's how to set began to say:


First, the preparatory work: 

1. Establish windows accounts
    were established a WINDOWS same user and password on A and B, is set to administrator privileges. In the present embodiment are set to the user name: pub, password: 1
 2 To ensure network connectivity
under A and B in SQL SERVER normal communication by computer name (required release the actual server name, you can not use the server's IP address. If IP subject to error). If A and B are not the same segment, may each modify the hosts file on the A, B alias server. A method is provided: A server such as modifying the hosts

<. 1> Notepad open the file - open - enter the file name:
<2> format: IP address of the computer name space + +. Then save and close. as follows:
ServerB 192.168.0.2
3. Set publish the directory where
the establishment of a shared directory on the publisher A, as the directory where the publication snapshot files. The case file was built in the D root directory folder named SqlCopy. Set the folder security options and the following figure:



Figure 2
 
4. SQL registration
 Publisher Subscriber A and B registered mutual steps are as follows:
Open A server in SQL Server Management Studio, hereinafter referred to as SSMS, open the View -> Registered Servers - > right database engine -> New server registration ----- remote server name (ServerB) to fill in to register -> authentication choose "SQL server authentication" -> username (sa) password -> create groups (or not built ) -> Done. Do the same on the server registered A. B
 

3

4

5. Set the SQL Agent (Publisher and Subscriber are set) 
to start the SQL Server Agent service are located in A and B, copy and subscription must rely on this service can take place. Then the agent start-up account to account pub created in step 1.
Setting method: open the configuration tool -> SQL Server Configuration Manager-> SQL SERVER 2005 Service -> Right SQL Server Agent (MSSSQLSERVER) -> Properties -> Select this account -> enter the account password pub 1-> Click OK.
Special Note: The agent start-up account can not avoid in service (Administrative Tools Control Panel --- --- Service) modified. This will lead to failure. By modifying SQL Server Configuration Manager, the system will do some additional settings such as pub will be added to the account SQLServer2005SQLAgentUser $ XX $ XX group.





5

6. Establish SQL login account
respectively in the A and B server, create the corresponding steps 1 system user login name pub in SQL Server, as the owner of the publication database PubTest (set dbo_owner and public). B as a subscription server, first create an empty database PubTest. PubTest consistent data structure and the A.
A first construction in pub account the following steps: the same operations on the B.













Second, the publishing server configuration (Configuration published on the Publisher A)

1. On the server A, open SSMS, to sa account login, opening the [Copy] -> right-click Local Publications], select [New publication].

  
9

2. Select the Next button, and then enter the new publication wizard, and if the first new release, there may be below 11, 13, or else do not experience these interfaces
If the SQL Agent service is not automatically started , there will be the interface 12.


10

11

12

13 
 3. Select the database PubTest [Next] you want to publish, where only the radio, you can not select multiple databases. 14

 
14 

 4. Next, select the type of release, according to your actual situation, select the appropriate type of release, in the present embodiment is selected [snapshot]
Snapshot: snapshot data distribution in a transient state of the particular time , without monitoring the updates to the data. When synchronization occurs, it will generate a complete snapshot and send it to subscribers. When one or more subject to the following conditions, the use of snapshot replication itself is the most appropriate:  
    1: Few changes to the data. 
    2: Allow a period of time with a copy of the data relative Publisher obsolete. 
    3: copy a small amount of data.  
 4: a large number of changes in the short term.   

Affairs: Transactional replication is typically used in server-to-server environment, suitable for transactional replication in the following cases:  
Ø 1: Incremental changes when you want to spread it to the subscriber.  
 2: changed from the publisher to change the arrival subscribers, the application needs the lag time between the two shorter. Ø  
   . 3: application requires access to an intermediate data state. For example, if a row changes five times, transactional replication will allow the application to respond to each change (for example, fired the trigger), not just in response to the final data of the line changes.
   4: Publisher large number of insert, update, and delete activities.  
 5: Publisher or Subscriber is not a SQL Server database (eg, Oracle).  

Transactions with updatable subscriptions publication:

transactional replication at the Subscriber support via updatable subscriptions, and peer replication to update. The following describes two updatable subscriptions:

Update Now. You must be connected to the publisher and the subscriber to update data at the Subscriber.

Queued updating. Without having to connect the publisher and subscriber server to update data at the Subscriber. It can be updated at the Subscriber or Publisher offline.

When the updated data at the subscriber, first dissemination of data to the Publisher, and then spread to other subscribers. If you are using Update Now, the two-phase commit protocol propagate changes immediately. If you are using queued updating, changes in stored in the queue; when the network connection is available, then asynchronous applications queued transactions in the Publisher. Because asynchronous updates propagate to the Publisher, the Publisher or another so the subscriber may have to update the same data, but when you apply the update conflict. The conflict resolution strategy based on conflict detection and resolution settings when creating publication.

If you create with updatable subscriptions publication affairs, will also enable the updating and queued updating as soon as the New Publication Wizard. If you create a publication using stored procedures, you can enable one or both options. When you create subscriptions to the publication, you can specify the update mode to use. If necessary, after the update you can switch between the two modes. For more information, see "Switching between the update mode" section below

Merge Replication: Replication normally used and the server to the client environment. Merge replication applies to the following circumstances:  
Ø  
  1: multiple Subscribers may update the same data at different times, and change it to spread to the Publisher and other Subscribers. 

2: Subscribers need to receive data, change data offline, and later synchronize changes with the Publisher and other Subscribers. Ø

  3: Each Subscriber requires a different data partitions.  
4: conflicts may occur, and in case of conflict, you need to have the ability to detect and resolve conflicts.  
5: application needs to change the final data results, rather than access to intermediate data states. For example, if prior to synchronize the Subscriber with the Publisher, the Subscriber line changed five times, then change the bank issued only once on the server to reflect the final data changes (that is, change the value of the fifth).  


15
5. Select and issued items and the row to be screened, in the present embodiment to select all.
  
    FIG 16
 
FIG 17 
 6. The configuration snapshot generation frequency and period, the timing of the following day 0:00 generate a new snapshot.

18 
 
19 
7. Set up a proxy account
method of operation as shown below: Click Security Settings pop-up Figure 21
 
Figure 20
Windows pub enter a previously created account, need to add in front of the computer name "ServerA \" connect to the Publisher, choose Usage. the following SQL server login name], input A sql server login name and password sa sa321.
 
21 
8. Next, create a publication. publishing operation is now complete. Back Project Test SSMS interface, just right-released, select [Start Replication Monitor] to see if there is an error. If there is no abnormality, you can set up a subscription.
 
22
 
23 
 Third, the subscription server settings
1. Log Subscriber B, you can log on A, B can log on locally from the open SSMS Manager, right-click [Local] subscription, select Subscribe [New].

Figure 24 
2. Select Publisher ServerA, verify mode selection [SQL Server] Enter the sa password authentication "sa123", the connection point
 

25 
 

26 
 Next 27 pop-up interface, select Test just released, click the Next button

27 
3. distribution agent to select the second position [run each agent at its Subscriber A] to reduce the burden on the server. Next point []
 
28 
4. Select PubTest subscription database built in advance, the next point []
 
29 
5 accounts provided, click eject button 31 is provided


Figure 30 
 , select [Run] in the following windows account interface in Figure 31, the input process account is an account previously established pub, enter the password 1.
The following connection to the distribution server, select [Use the following SQL Server login name], that is, SQL server a login name "sa" and the password "sa123", and then given to determine, in Figure 30, click Next

31 
 

32 
 6. set the running program can be set to run according to plan, where the election is continuous operation ,


33  
select initialize Now, the next step, the last point [Finish] to start creating subscribe progress screen Figure 37.

Figure 34  

35  

36 

37 
 7. back to SSMS interface, the subscription right PubTest created, choose View sync status [] to see if the run and errors.


 
 

 
Fourth, the solutions to common problems
 occur when 1. Publish "can not begin to Step 2 (reason: Error validating \ identity XX XX agents, system error: Logon failure: unknown user name or bad password.) The step failed. "Resolution hit SP2 patch above.
2. "The process could not read file" XX \ unc \ GSEOMARKSERVER1_PRODAAMS_TESTMERGE \ 20130223095566 \ xxxx_2.pre ". ( Source: MSSQL_REPL, Error Number: MSSQL_REPL20016) Get help: http: // help / MSSQL_REPL20016 system can not find the path specified. "
solution: Subscribe to specify the directory to be released after the directory server.

Guess you like

Origin www.cnblogs.com/SyncNavigator8-4-1/p/10974380.html