Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did the following to get Sync Framework working using WCF with SQL Server 2008</p> <ul> <li>Enabled Change Tracking in SQL Server 2008</li> <li>Enabled change tracking for tables participating in the Sync</li> <li>Added a metadata table named anchor </li> <li>Added a table to track client Ids named "guid"</li> <li>Used SqlExpressClientSyncProvider available from MSF's codeplex project site as Client Sync Provider</li> <li><p>Used SqlSyncAdapterBuilder to build adapters for tables participating in the Sync</p> <pre><code>foreach (var item in anchorTables) { // Use adapter builder to generate T-SQL for querying change tracking data and CRUD SqlSyncAdapterBuilder builder = new SqlSyncAdapterBuilder(); builder.Connection = new SqlConnection(this.connectionStringFactory.ConnectionString); builder.ChangeTrackingType = ChangeTrackingType.SqlServerChangeTracking; builder.SyncDirection = SyncDirection.Bidirectional; builder.TableName = item.TableName; // Get sync adapters from builder SyncAdapter clientAdapter = builder.ToSyncAdapter(); clientAdapter.TableName = item.TableName; this.clientSyncProvider.SyncAdapters.Add(clientAdapter); } </code></pre></li> <li><p>Added anchor commands</p> <pre><code>SqlCommand anchroCommand = new SqlCommand { CommandText = "SELECT @" + SyncSession.SyncNewReceivedAnchor + " = change_tracking_current_version()" }; anchroCommand.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.BigInt) .Direction = ParameterDirection.Output; this.clientSyncProvider.SelectNewAnchorCommand = anchroCommand; </code></pre></li> <li><p>Implemented a WCF Service using a instance of DbServerSyncProvider functioning as Server sync provider. You will have generate sync adapters and set anchor command as shown in previous step for Server provider too.</p> <pre><code>[ServiceContract] public interface ISyncService { [OperationContract] SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession); [OperationContract] SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession); [OperationContract] SyncSchema GetSchema(Collection&lt;string&gt; tableNames, SyncSession syncSession); [OperationContract] SyncServerInfo GetServerInfo(SyncSession syncSession); } </code></pre></li> <li><p>Created a proxy class implementing ServerSyncProvider to access WCF service</p> <pre><code>public class DbServerSyncProviderProxy : ServerSyncProvider { SyncServiceProxy.SyncServiceClient serviceProxy = new SyncServiceProxy.SyncServiceClient(); public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession) { return serviceProxy.ApplyChanges(groupMetadata, dataSet, syncSession); } } </code></pre></li> <li>Created an instance of SyncAgent and set RemoteProvider with an instance of proxy class which is used to access WCF service. LocalProvider is set with instance of SqlExpressClientSyncProvider</li> <li>Added tables and sync groups to SyncAgent configuration</li> <li>SyncAgent.Synchronize()</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload