Using SQL Merge and SQL Distribution Controls in a Web Application

Replication Programming

Replication Programming

Using SQL Merge and SQL Distribution Controls in a Web Application

The programs in the replctrl folder are samples of how to include the SQL Merge control and the SQL Distribution control in a custom application. This sample is located in C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\sqlrepl\replctrl.

To run the sample programs

  1. On the computer that will be a Publisher with a local Distributor, verify that the SQL Server Agent is running. If it is not running, start it.

  2. Open SQL Query Analyzer, open \Samples\sqlrepl\replctrl\instsamp.sql, and then run instsamp.sql. This SQL script configures the computer for publishing and distribution, enables the computer as a Subscriber, adds a distribution database with the name distributor, creates a transactional publication named SampleTransactionalPublication and a merge publication named SampleMergePublication. instsamp.sql creates a Snapshot Agent for both publications.

  3. The instsamp.sql creates pull and push subscriptions for each publication and creates and configures a database called Northwind_replica as the subscription database. Any warnings from the script regarding tables that have been created with a maximum row size that exceeds the maximum number of bytes per row can be ignored.

    The Northwind database will have two publications: SampleTransactionalPublication and SampleMergePublication. The SQL Server contains a new subscription database, Northwind_replica.

  4. After the instsamp.sql script has completed successfully, in SQL Server Enterprise Manager, expand Replication Monitor, expand the Agents folder, and then click the Snapshot Agents folder. In the right pane, for each agent listed, right-click, and then click Start Agent. This starts the Snapshot Agent and creates a snapshot for each publication.

To modify the HTML sample program

  1. Open the \Samples\sqlrepl\replctrl\html\replsamp.htm file in Notepad or other HTML editor. There are comments in the file noting that the local computer name needs to be specified in the line of code following the comment.

  2. Save and the file.

To execute the HTML sample program

  • Using Microsoft Internet Explorer or another Internet browser, open the replsamp.htm file. These options are available:

Synchronize Transactional Subscription

Runs the Distribution Agent and applies the snapshot data and schema at the subscription database, Northwind_replica. After the HTML page has completed, the snapshot will be applied, and the Northwind_replica database will show the new tables, with each table corresponding to an article from the publication. The distribution activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.

Synchronize Merge Subscription

Runs the Merge Agent and applies the snapshot data and schema at the subscription database, Northwind_replica. After the HTML Page has completed, the snapshot will be replicated, and the Northwind_replica database will show the new tables, with each table corresponding to an article from the publication. The merge activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.