Introduction

Demonstrates how to use Microsoft Synchronization Services for ADO.NET for two-tier download-only synchronization.

Requirements

This sample requires that you have the Northwind database installed on a test server. For more information, see How to: Install and Troubleshoot Database Components for Samples.

Building the Sample

  1. Run the server database script that is in the SQL Scripts folder under the project root. This sets up the tables for change tracking.

  2. Open the sample solution in Visual Studio.

  3. Change the server connection string to connect to the Northwind database on your test server:

    1. Double-click the My Project node for each project.

    2. Click Settings.

    3. Change the connection string.

  4. Press F5 to build and run the sample.

Description

The sample demonstrates synchronization. Click Synchronize in the sample application. This downloads data from the server to the .sdf file. Next, make data changes in the server data grid, and then click the save button.

Click Synchronize again to download your changes to the client.

Screenshot

Sample Code

Visual Basic
Edit|Remove
Public Class MainForm 
 
    Private Sub CustomersBindingNavigatorSaveItem_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles CustomersBindingNavigatorSaveItem.Click 
        Me.Validate() 
        Me.CustomersBindingSource.EndEdit() 
        Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet) 
    End Sub 
 
    Private Sub MainForm_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load 
        Me.CustomersTableAdapter.Fill(Me.NorthwindDataSet.Customers) 
        Me.CustomersTableAdapter1.Fill(Me.CacheDataSet.Customers) 
    End Sub 
 
    Private Sub btnSynchronize_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnSynchronize.Click 
        ' Instantiate the cache sync agent and call Synchronize() 
        ' The Synchoronize method returns a SyncStatistics object 
        Dim cacheAgent As New CacheSyncAgent 
 
        Dim syncStats = cacheAgent.Synchronize() 
 
        ' Display sync start and end times 
        Me.txtBoxStartTime.Text = syncStats.SyncStartTime.ToString 
        Me.txtBoxEndTime.Text = syncStats.SyncCompleteTime.ToString 
 
        Me.txtBoxDLoaded.Text = syncStats.TotalChangesDownloaded 
        Me.txtBoxApplied.Text = syncStats.DownloadChangesApplied 
 
        Me.CustomersTableAdapter1.Fill(Me.CacheDataSet.Customers) 
    End Sub 
End Class

Source Code Files

More Information

For more information on Occasionally Connected Data: http://social.msdn.microsoft.com/Search/en-US?query=occasionally%20connected%20data