This Sample shows how to use the Sync Framework 2.1 database providers to configure and execute synchronization between a SQL Server database and one or more SQL Server Express databases. It demonstrates syncing with a central server as well as between two clients and is targeted at customers who want to leverage SQL Express on the client instead of SQL Compact to take advantage of features such as stored procedures, XML support, and advanced profiling.

What is Demonstrated in This Sample:
Required Software:

What is Demonstrated in This Sample?

- Synchronizing a database scope with multiple instances of SQL Server/SQL Express databases.
- Enabling synchronization over a 2-tier model.
- The new multi-scope change-tracking model on the server.
- Configuration of SqlSyncProvider objects.
- Enabling batched synchronization.

How Do I Install the Application?

  1. Connect to an instance of SQL Server, and open and execute peer1_setup.sql.
  2. Open demo.sql and execute the "Insert Sample Data In Tables" sections at the top of the script.
  3. In Visual Studio, open the SharingAppDemo-SqlProviderEndToEnd solution .
  4. Build the project.

What Do the Individual CS Files Contain?

  1.  App directory - Contains all the code files for the Windows Form app.
  2.  App\SqlCreationUtilities.cs - Contains utility classes that the app uses to handle string constants and hold peer database information.
  3.  App\SqlSharingForm.cs - Main entrance point for the Windows Form app. Contains all GUI eventing/OnClick logic.
  4.  App\NewSqlPeerCreationWizard.cs - New wizard app that is used to gather user information to configure and provision a new SQL Server or SQL Express database.
  5.  App\ProgressForm.cs - Form app that shows progress information for each SyncOrchestrator.Synchronize() call.
  6.  App\Resource.resx and App\Resources.Designer.cs - Resource files.
  7.  App\SharingApp.cs - Contains the Main function that launches a new instance of the SqlSharingForm class.
  8.  App\SynchronizationHelper.cs - The main class that handles configuration SqlSyncProvider instances. Short instructions are included for each method in the class:
  9.  CheckAndCreateSQLDatabase() - Utility function that creates an empty SQL Server database.
  10.  CheckIfProviderNeedsSchema() - Sample that demonstrates how a SqlSyncProvider would determine if the underlying database needs a schema or not.
  11.  ConfigureSqlSyncProvider() - Sample that demonstrates how to configure SqlSyncProvider.
  12.  provider_*() - Sample client side event registration code that demonstrates how to handle specific events raised by Sync Framework.
  13.  App\TablesViewControl.cs - Custom user control that displays values from the two sample tables (orders and order_details).
  14. Setup directory - Contains the server provisioning .sql files.

How Do I Use the Sample?

  1. Install the application as described in the "How Do I Install" section.
  2. Run the sample app. It assumes that SQL Server is installed as localhost. If it's not, please replace Environment.MachineName with the correct instance name in SqlSharingForm.SqlSharingForm_Shown().
  3. If the sample is correctly installed, values from the orders and order_details tables should display in the datagrid on the "Peer1" tab.
  4. The Synchronize button is disabled until at least one new SQL Server peer is added. Add a new SQL Server database by clicking "Add SQL Peer". SQL Server can be on local or remote machines with Windows NT integrated security or the given username and password.
  5. On clicking OK, a new tab with the name "Peer#" should be added to the main form. After the peer is synchronized, clicking that tab displays values for the tables orders and order_details in that SQL Server database.
  6. Batching can be enabled by setting a non-zero value in the Batch size text box. By default batching is disabled.
    6.a The Batching location can be modified by clicking on the Change button.
  7. To synchronize, select source and destination providers, and click Synchronize.
    Make changes to one or more database tables of different peers and then try to synchronize the peers to confirm that changes are synchronized.

For more information on synchronizing databases, see Synchronizing SQL Server and SQL Server Compact.

Note: If you use Visual Studio 2010 to compile these samples, you will first need to remove references to the Sync Framework assemblies and then re-add the assembly references to the projects. Otherwise, you will see "type or namespace name could not be found" compilation errors.