This application demonstrates 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 Compact databases. This sample demonstrates syncing with a central server as well as between two clients.


What is Demonstrated in This Sample?


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" section at the top of the script.
  3. In Visual Studio, open the SharingAppDemo-CEProviderEndToEnd 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\CeCreationUtilities.cs - Contains utility classes that the app uses to handle string constants and hold client database information.
  3. App\CESharingForm.cs - Main entrance point for the Window Form app. Contains all GUI eventing/OnClick logic.
  4. App\NewCEClientCreationWizard.cs - New wizard app that is used to gather user information to configure and provision a new Compact client 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 CESharingForm class.
  8. App\SynchronizationHelper.cs - The main class that handles configuration of server side SqlSyncProvider and client side SqlCESyncProvider instances. Short instructions are included for each method in the class:
  9. CheckAndCreateCEDatabase() - Utility function that creates an empty Compact database.
  10. CheckIfProviderNeedsSchema() - Sample that demonstrates how a Compact provider would determine if the underlying database needs schema or not.
  11. ConfigureCESyncProvider() - Sample that demonstrates how to configure SqlCeSyncProvider and provision the underlying database.
  12. ConfigureSqlSyncProvider() - Sample that demonstrates how to configure SqlSyncProvider and provision the underlying database.
  13. provider_*() - Sample client side event registration code that demonstrates how to handle specific events raised by Sync Framework.
  14. App\TablesViewControl.cs - Custom user control that displays values from the two sample tables (orders and order_details), based on the client and server connections that are passed in.
  15. Setup directory - Contains the server provisioning .sql files.

How Do I Use the Sample?

  1. Install the application as described in the "How to install" section.
  2. Run the sample app. By default it assumes that SQL Server is installed as localhost. If it's not, then change the server from Environment.MachineName to the desired server in the CESharingForm_Shown() method.
  3. If the sample is correctly installed, values from the orders and order_details should display in the datagrid on the "Server" tab.
  4. The Synchronize button is disabled until at least one Compact client is added. Add a new Compact client database by clicking "Add CE Client". Options for creating a new client in the New CE Creation Wizard:
     * Full initialization - Create an empty Compact database, get the schema from the server, create the schema on the client, and get all data from the server on the first Synchronize() call.
     * Snapshot initialization - Export an existing Compact database, initialize that snapshot and receive only incremental changes from the server on the first Synchronize() call.
  5. For full initialization, select the location and file name Or For snapshot initialization, select the .sdf file of an existing client (in the same scope) and pick the location and name for the exported database.
  6. On clicking OK, a new tab with the name "Client#" should be added to the main form. After the client is synchronized, clicking that tab displays values for the tables orders and order_details in that Compact database. 
  7. Batching can be enabled by setting a non zero value in the Batch size text box. By default batching is turned off.
    7.a Batching location can be modified from by clicking on the Change button.
  8. To synchronize, select source and destination providers, and click Synchronize.
  9. Make changes to the server or client database tables and then try to synchronize the peers to confirm that changes are synchronized.

Required Software
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.