Using SQL Merge and SQL Distribution Controls in a Custom Visual C++ Application

Replication Programming

Replication Programming

Using SQL Merge and SQL Distribution Controls in a Custom Visual C++ 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 creates a merge publication named SampleMergePublication.

  3. The instsamp.sql script 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 computer is now configured as a Publisher with a local Distributor and is enabled as a Subscriber. The Northwind database will have two publications: SampleTransactionalPublication and SampleMergePublication. The instance of 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 use the Microsoft Visual C++® sample code that demonstrates how to include the SQL Distribution control and the SQL Merge control in a custom application, the two programs must first be built into executables.

To build the distribution sample executable using Visual C++

  1. Open Visual C++. On the main menu, click File, click Open Workspace, navigate to the C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp directory, and then open distsamp.dsw.

  2. On the Tools menu, click Options, and then on the Directories tab, in the Show directories for drop-down list, select Include files. Add the path C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Include. This path assumes the samples were installed to the default directory. If this path does not exist, navigate to the path where the include files were installed.

  3. On the Directories tab, in the Show directories for drop-down list, click Library files, and then add the path C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Lib.

    This path assumes the samples were installed to the default directory. If this path does not exist, navigate to the path where the Lib files were installed.

  4. On the Build menu, click Build distsamp.exe. The default location of the resulting distsamp.exe will be in C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp\Debug or C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp\Release, depending on the build configuration.

To build the distribution sample executable using a batch command

  1. Open a command prompt window.

  2. Navigate to C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp.

  3. Run the batch file builddst.cmd with the following parameters:

    builddst.cmd [x86] [debug|retail] [clean]

    • Enter builddst.cmd /? for help.

To run the sample, run the executable from its location using a command prompt window.

The distsamp.exe sample activates the Distribution Agent and moves the data from the snapshot into the tables defined as articles for the transactional subscription in the database Northwind_replica.

To build the merge sample executable using Microsoft Visual C++.

  1. Open Visual C++. On the main menu, click File, click Open Workspace, and then navigate to the C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp directory and open mergsamp.dsw.

  2. On the Tools menu, click Options, and then on the Directories tab, in the Show directories for drop-down list, click Include files. Add the path C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Include.

    This path assumes the samples were installed to the default directory. If this path does not exist, navigate to the path where the include files were installed.

  3. On the Directories tab, in the Show directories for drop-down list, click Library files, and then add the path C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Lib.

    This path assumes the samples were installed to the default directory. If this path does not exist, navigate to the path where the Lib files were installed.

  4. On the Build menu, click Build mergsamp.exe. The default location of the resulting mergsamp.exe will be in C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp\Debug or C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp\Release, depending on the build configuration.

To build the merge sample executable using a batch command

  1. Open a command prompt window.

  2. Navigate to C:\Program Files Microsoft SQL Server\80\Tools\Devtools\Samples\sqlrepl\replctrl\cpp.

  3. Run the batch file buildmrg.cmd with the following parameters:

    buildmrg.cmd [x86] [debug|retail] [clean]

    Enter buildmrg.cmd /? for help.

To run the sample, run the executable from its location using a command prompt window.

The mergsamp.exe sample activates the Merge Agent and moves data from the snapshot into the tables defined as articles for the merge subscription in the Northwind_replica_html database.