Data Synchronization in SQL Server 2000

Source: Internet
Author: User
Tags mssqlserver network function
Document directory
  • Data Synchronization in SQL Server 2000
Data Synchronization in SQL Server 2000

 

1. whether the ms SQL Server and SQL Server Agent services are started and run as domain users (. \ administrator users are also allowed) If you log on to the local account, the network function is not available and the following error occurs: the process failed to connect to the distributor '@ server name' (If your server has used the full-text retrieval service of SQL Server, do not modify the local startup of MSSQLServer and SQLServerAgent services. The full-text search service is unavailable. Use another machine as the distribution server for replication in SQL Server .)

To modify the login user who starts the service, you must restart the MSSQLServer and SQLServerAgent services to take effect.

2. Check whether the names of the related SQL Server servers have been changed. (The srvname and datasource must be the same on the local machine with srvid = 0)

Run the following command in the query Analyzer:

 

use master 
select srvid,srvname,datasource from sysservers

If there is no srvid = 0 or srvid = 0 (that is, the current machine) but the srvname is different from the datasource, You need to modify it as follows:

 

Use master
Go
-- Set two variables
Declare @ serverproperty_servername varchar (100 ),
@ Servername varchar (100)
-- Obtain information about the Windows NT server and the instance associated with the specified SQL server instance
Select @ serverproperty_servername = convert (varchar (100), serverproperty ('servername '))
-- Returns the name of the local server running Microsoft SQL Server.
Select @ servername = convert (varchar (100), @ servername)
-- Display the obtained Parameters
Select @ serverproperty_servername, @ servername
-- If @ serverproperty_servername is different from @ servername (because you changed the computer name), run the following
-- Delete the wrong server name
Exec sp_dropserver @ Server = @ servername
-- Add the correct server name
Exec sp_addserver @ Server = @ serverproperty_servername, @ local = 'local'

To modify this parameter, you must restart the MSSQLServer and SQLServerAgent services to take effect.

In this way, errors 18482 and 18483 will not occur during replication creation.

3. Check whether the registration names of the SQL Server related to the SQL Server Enterprise Manager are the same as those described in the second section above.

You cannot use the registration name of an IP address. (We can delete the registration of IP addresses and create a new server name registered as an SQL Server administrator) in this way, errors 14010, 20084, 18456, 18482, and 18483 will not occur during replication creation.

4. Check whether the network of Several SQL Server servers can be accessed normally.

If you can ping the Host IP address but cannot ping the host name, you must

 

winnt\system32\drivers\etc\hosts (WIN2000) 
windows\system32\drivers\etc\hosts (WIN2003)

The correspondence between the IP address of the database server and the host name.

For example:

 

127.0.0.1 localhost 
192.168.0.35 oracledb oracledb
192.168.0.65 fengyu02 fengyu02
202.84.10.193 bj_db bj_db

Or create an alias in the SQL Server Client Network utility.

5. Whether the extended storage process required by the system exists (if it does not exist, it needs to be restored ):

sp_addextendedproc 'xp_regenumvalues',@dllname ='xpstar.dll' 
go
sp_addextendedproc 'xp_regdeletevalue',@dllname ='xpstar.dll'
go
sp_addextendedproc 'xp_regdeletekey',@dllname ='xpstar.dll'
go
sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'

Next, you can use the [copy]-> right-click and choose-> [configure Publishing, subscription server, and Distribution] GUI in the SQL Server Enterprise Manager to configure database replication.

The steps for configuring replication are as follows:

1. Create a distribution server [welcome to the configuration release and distribution wizard]-> [select a distribution server]-> [make "@ servername" its own distribution server, SQL Server will create a distribution database and log]-> [Create a snapshot folder]-> [custom configuration]-> [No, use the following default configuration]-> [complete]

After the preceding steps are completed, a distribion library and a distributor_admin administrator-level user will be created in the current "@ servername" SQL Server database (we can change the password at will)

Four new jobs are added to the server:

[Clear Agent history: distribution]

[Clear Distribution: distribution]

[Copy proxy check]

[Re-initialize a subscription with failed data verification]

The SQL Server Enterprise Manager has a replication Monitor, which allows you to publish, distribute, and subscribe to the current machine.

In SQL Server Enterprise Manager, we [copy] Again-> right-click and choose-> [configure Publishing, subscription server, and Distribution]

You can go to the [attributes of the Publishing Server and the distribution server] WINDOW> [Publishing Server]> [add]> [OK]> [Publishing Database]> [transaction] /[merge]-> [OK]-> [subscription server]-> [add]-> [OK] add other SQL Server servers on the network as release or subscription servers.

Replication is a technology that copies a set of data from one data source to multiple data sources. It is an effective way to publish a set of data to multiple storage sites. With the replication technology, users can publish a copy of data to multiple servers, so that different server users can share the data within the permitted range of permissions. The replication technology ensures that data distributed in different locations is automatically updated synchronously to ensure data consistency.

The basic elements of SQL replication include

Publishing Server, subscription server, distribution server, publications, articles

How SQL replication works

SQL Server mainly uses publications and subscriptions to process replication. The server on which the source data is located is the publishing server, which is responsible for publishing data. The Publishing Server copies all changes to the data to be published to the distribution server. The distribution server contains a distribution database that can receive all changes to the data and save the changes, and then distribute the changes to the subscription server.

SQL Server replication technology type

SQL Server provides three Replication technologies:

1. Copy a snapshot (this will be used if we stay there)

2. Transaction Replication

3. Merge and copy

As long as the above concepts are clarified, we will have a certain understanding of replication. Next we will perform the copy step.

First, configure the Publishing Server

(1) Select the specified [server] Node

(2) Select the [Publish, subscribe server, and distribute] command from the [copy] sub-menu in the [tools] drop-down menu.

(3) In the dialog box that appears, click [next] And then follow the prompts until the operation is completed.

(4) After setting the Publishing Server, the system adds a replication monitor to the tree structure of the server. A distribution database (distribution) is also generated)

Create a publication

(1) Select the specified server

(2) Select the [create and manage release] command from the [copy] sub-menu in the [tools] menu. A dialog box is displayed.

(3) Select the database for which you want to create the publication, and click [Create release]

(4) In the prompt dialog box of the [Create release wizard], click [next]. A dialog box is displayed. The dialog box contains three types of copies. Now we select the first one, that is, the default snapshot release (the other two can be checked for help)

(5) Click [next] system requirements to specify the type of database server that can subscribe to the release. sqlserver allows data replication between different databases, such as oracle or access. But here we choose to run the database server "SQL Server 2000"

(6) Click [next]. A dialog box for defining the document is displayed, that is, the table to be published.

(7) then [next] until the operation is completed. After the publication is created, the database for creating the publication becomes a shared database.

Design subscription

(1) Select the specified subscription Server

(2) select [request subscription] from the [tools] drop-down menu in the [copy] submenu

(3) Click [next] until the system prompts you to check the running status of the SQL Server proxy service. The precondition for performing the copy operation is that the SQL Server proxy service must be started.

(4) Click [finish]. Complete the subscription operation.

The above steps are actually copied successfully. But how can we know whether the replication is successful? This method can be used to quickly check whether the operation is successful. Expand copy under the Publishing Server -- publish content -- Right-click Publish content -- properties -- click live -- status, and then click Run Agent immediately. Then click agent properties, click live scheduling, and set Scheduling to every day. occurred, every minute, between 0:00:00 and 23:59:59. The next step is to determine whether the replication succeeds and enable C: \ Program Files \ Microsoft SQL Server \ MSSQL \ repldata \ UNC \ xiaowangzi_database_database check whether there are some folders that use time as the file name. If you do not believe it, open your database. Check the subscription server's specified subscription database to see if you have seen the table you just released-A Manual

Synchronization scheme

 

-- Example:

-- Test environment, SQL Server, remote server name: xz, User name: SA, no password, Test Database: Test

-- Tables on the server (query analyzer is connected to a table created on the server)

Create Table [user] (ID int primary key, number varchar (4), name varchar (10 ))
Go
-- Perform the following operations on the LAN (Local Machine)
-- Local table, State Description: NULL indicates new record, 1 indicates modified record, 0 indicates no change record
If exists (select * From DBO. sysobjects where id = object_id (n' [user] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [user]
Go
Create Table [user] (ID int identity (1, 1), number varchar (4), name varchar (10), State bit)
Go
-- Create a trigger to maintain the value of the state field
Create trigger t_state on [user]
After update
As
Update [user] Set state = 1
From [user] A join inserted B on A. ID = B. ID
Where a. State is not null
Go
-- To facilitate synchronization, create a connection server to the server to be synchronized
-- The remote server name is xz, the user name is SA, and no password is required.
If exists (select 1 from Master .. sysservers where srvname = 'srv _ lnk ')
Exec sp_dropserver 'srv _ lnk ', 'droplogins'
Go
Exec sp_addmediaserver 'srv _ lnk ', '', 'sqloledb', 'xz'
Exec sp_add1_srvlogin 'srv _ lnk ', 'false', null, 'sa'
Go
-- Create a stored procedure for synchronization
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [p_synchro] ') and objectproperty (ID, n' isprocedure') = 1)
Drop procedure [DBO]. [p_synchro]
Go
Create proc p_synchro
As
-- Set xact_abort on
-- Start the MSDTC Service of the remote server
-- Exec master .. xp_mongoshell 'isql/s "xz"/u "sa"/P ""/Q "Exec master .. xp_cmdshell ''net start MSDTC '', no_output" ', no_output
-- Start the MSDTC Service of the Local Machine
-- Exec master.. xp_cmdshell 'net start MSDTC ', no_output
-- Performs distributed transaction processing. If the table uses the ID column as the primary key, use the following method:
-- Begin Distributed Transaction
-- Synchronize Deleted Data
Delete from srv_lnk.test.dbo. [user]
Where id not in (select ID from [user])
-- Synchronize new data
Insert into srv_lnk.test.dbo. [user]
Select ID, number, name from [user] Where state is null
-- Synchronize modified data
Update srv_lnk.test.dbo. [user] Set
Number = B. number, name = B. Name
From srv_lnk.test.dbo. [user]
Join [user] B on A. ID = B. ID
Where B. State = 1
-- Update the local flag after synchronization
Update [user] Set state = 0 where isnull (State, 1) = 1
-- Commit tran
Go
-- Create a job and regularly execute the data synchronization Stored Procedure
If exists (select 1 from MSDB .. sysjobs where name = 'data ')
Execute MSDB. DBO. sp_delete_job @ job_name = 'data'
Exec MSDB .. sp_add_job @ job_name = 'data'
-- Create a job
Declare @ SQL varchar (800), @ dbname varchar (250)
Select @ SQL = 'exec p_synchro '-- Data Processing Command
, @ Dbname = db_name () -- Name of the database for processing data
Exec MSDB .. sp_add_jobstep @ job_name = 'data ',
@ Step_name = 'data synchronization ',
@ Subsystem = 'tsql ',
@ Database_name = @ dbname,
@ Command = @ SQL,
@ Retry_attempts = 5, -- number of retries
@ Retry_interval = 5 -- Retry Interval
-- Create Scheduling
Exec MSDB .. sp_add_jobschedule @ job_name = 'data ',
@ Name = 'schedule ',
@ Freq_type = 4, -- daily
@ Freq_interval = 1, -- run once a day
@ Active_start_time = 00000 -- execute at 0
Go

Related Article

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.