This project is read-only.

SyncFx Stored Procedure Generator Documentation

  • What is it for?
    • Enable developers to quickly create and edit stored procedures from a SQL Server 2008 database.
  • What does it do?
    • Microsoft Sync Framework 2.0 requires eight stored procedures for each change tracking table. This creates a collection SP scripts for each table.
  • Limitations
    • Must use SQL Server 2008.
    • Must have change tracking enabled on database.
  • Tutorial
  • Open SQL Server 2008 and create a database named "SyncSamplesDbChangeTrackingCustom".
  • Run the following scripts found in the same order displayed. These can be found in the SyncSamplesDbSetupScripts directory of the project. These will set up database and insert some data.
    1. SyncSamplesDbChangeTrackingCustom_DDL.sql
    2. SyncSamplesDbChangeTrackingCustom_DataLoad.sql
    3. SyncSamplesDbChangeTrackingCustomENABLECHANGE_TRACKING.sql
  • Create new windows forms project (SyncGenDemo).
  • Include the following references
    1. Microsoft.Synchronization Version 2.0.0.0
    2. Microsoft.Synchronization.Data Version 1.0.0.0
    3. Microsoft.Synchronization.Data.Server Version 1.0.0.0
    4. Microsoft.Synchronization.Data.SqlServerCe Version 3.5.0.0
    5. System.Data.SqlServerCe Version 3.5.1.0
  • Create the following directories:
    1. Sync
    2. Generated: Under Sync
    3. SyncAdapters: Under Generated
    4. SyncTables: Under Generated
    5. Custom: Under Sync
    6. Templates: Under Sync
  • Create server connection string in Settings and call it ServerConnectionString
  • In Template directory created above do following:
    1. Right click add new
    2. Select Script template in Code Generation tab
    3. Name it SyncFxObjectScript.tt
    4. Copy and paste contents of C:\Program Files\SyncFxProcObjectGenerator\SyncFxObjectGenerator\ SyncFxObjectScript.tt into file created
    5. Update the following variables with local machine.
      1. string projectHome = @"C:\SyncFxGeneratorSampleApplication\SyncGenDemo\";
      2. string projectName = "SyncGenDemo";
      3. string serverName = "BAH536231Tabit2";
      4. string dbName = "SyncSamplesDbChangeTrackingCustom";
      5. bool generateClientDb = true
      6. string clientDbName = "SyncSampleClient";
    6. Click Save, this generates everything.
  • Click view all files in project.
  • Right click SyncSampleClient.sdf and click include in project
  • Name dataset SyncSampleClientDataSet, select all tables
  • Click data show data sources
  • Drag the Customer table Form2.cs designer
  • Add button to Form1.designer and add following to click event:
    // Call SyncAgent.Synchronize() to initiate the synchronization process.
                // Synchronization only updates the local database, not your project's data source.
                SyncGenDemoSampleDataCacheSyncAgent syncAgent = new SyncGenDemoSampleDataCacheSyncAgent();
                Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
    
    
                string syncStatsStr = "";
                syncStatsStr += "DownloadChangesApplied =" + syncStats.DownloadChangesApplied.ToString() + Environment.NewLine;
                syncStatsStr += "DownloadChangesFailed =" + syncStats.DownloadChangesFailed.ToString() + Environment.NewLine;
                syncStatsStr += "TotalChangesDownloaded =" + syncStats.TotalChangesDownloaded.ToString() + Environment.NewLine;
                syncStatsStr += "TotalChangesUploaded =" + syncStats.TotalChangesUploaded.ToString() + Environment.NewLine;
                syncStatsStr += "UploadChangesApplied =" + syncStats.UploadChangesApplied.ToString() + Environment.NewLine;
                syncStatsStr += "UploadChangesFailed =" + syncStats.UploadChangesFailed.ToString() + Environment.NewLine;
                syncStatsStr += "SyncStartTime =" + syncStats.SyncStartTime.ToString() + Environment.NewLine;
                syncStatsStr += "SyncCompleteTime =" + syncStats.SyncCompleteTime.ToString() + Environment.NewLine;
    
                MessageBox.Show(syncStatsStr);
    
                // TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
                this.syncSampleClientDataSet.Customer.Merge(this.customerTableAdapter.GetData());
    
    


    That's it run the application and click button to sync.

Last edited Dec 15, 2009 at 1:27 PM by rtabit, version 12

Comments

rlarno Dec 17, 2009 at 3:44 PM 
Note: you'll need the T4Toolbox to be able to run this: http://www.codeplex.com/t4toolbox