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:
- Synchronizing a server database scope (hosted in a SQL Server or SQL Server Express instance) with multiple client-side instances of SQL Server or SQL Express
- The new multi-scope change-tracking model on the server
- Full initialization of the client side databases
- Configuration of SqlSyncProvider for both the server and client
- Enabling batched synchronization
- Visual Studio 2008
- .NET Framework 2.0 SP1 or .NET Framework 3.x
- Microsoft Sync Framework 2.1
- SQL Server Compact 3.5 sp2
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?
- Connect to an instance of SQL Server, and open and execute peer1_setup.sql.
- Open demo.sql and execute the "Insert Sample Data In Tables" sections at the top of the script.
- In Visual Studio, open the SharingAppDemo-SqlProviderEndToEnd solution .
- Build the project.
What Do the Individual CS Files Contain?
- App directory - Contains all the code files for the Windows Form app.
- App\SqlCreationUtilities.cs - Contains utility classes that the app uses to handle string constants and hold peer database information.
- App\SqlSharingForm.cs - Main entrance point for the Windows Form app. Contains all GUI eventing/OnClick logic.
- 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.
- App\ProgressForm.cs - Form app that shows progress information for each SyncOrchestrator.Synchronize() call.
- App\Resource.resx and App\Resources.Designer.cs - Resource files.
- App\SharingApp.cs - Contains the Main function that launches a new instance of the SqlSharingForm class.
- App\SynchronizationHelper.cs - The main class that handles configuration SqlSyncProvider instances. Short instructions are included for each method in the class:
- CheckAndCreateSQLDatabase() - Utility function that creates an empty SQL Server database.
- CheckIfProviderNeedsSchema() - Sample that demonstrates how a SqlSyncProvider would determine if the underlying database needs a schema or not.
- ConfigureSqlSyncProvider() - Sample that demonstrates how to configure SqlSyncProvider.
- provider_*() - Sample client side event registration code that demonstrates how to handle specific events raised by Sync Framework.
- App\TablesViewControl.cs - Custom user control that displays values from the two sample tables (orders and order_details).
- Setup directory - Contains the server provisioning .sql files.
How Do I Use the Sample?
- Install the application as described in the "How Do I Install" section.
- 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().
- If the sample is correctly installed, values from the orders and order_details tables should display in the datagrid on the "Peer1" tab.
- 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.
- 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.
- 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.
- 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.