• 数据同步框架MS Sync Framework IDE快速开发支持Local Database Cache


    数据同步框架MS Sync Framework [术语、例子、参考资料、Tips]

    http://www.cnblogs.com/2018/archive/2011/02/22/1961654.html 

    数据同步框架MS Sync Framework-不同场景使用例子和简要分析

    http://www.cnblogs.com/2018/archive/2011/02/23/1961657.html

    以上两篇文章对框架的基础有了描述,通过IDE的提供Local Database Cache可以快速的实现一个常用的同步应用。具体如下:

    VS 提供的基于MS Sync框架的支持,用于客户端离线的使用,客户端是SQL Compact,服务端可以是Sql Server 2005/2008

     

    详细例子参考:

    http://cid-56b433ad3d1871e3.office.live.com/self.aspx/.Public/SyncTest.rar 

    DbCache目录下是具体的例子,具体的建立步骤如下

    模板

    image

    加入后会有*.sync文件,以后双击 这个可编辑和修改

    同步设置

    双击NorthWind.Server.sync 或NorthWind.Server.sync可以进行修改

    image

    SQL Server 2008是可以使用Sql Server change Tracking

    SQLScripts SQLUndoScripts : 对数据库的Provison的支持和取消

    NorthwindDataSet.xsd: 客户端的缓存访问接口

    同步代码

                using (DataServiceProxy.NorthWindSyncContractClient DataSvc = new DataServiceProxy.NorthWindSyncContractClient())
                {                 ///nwCache.sdf把默认建表时的数据同步下来
                    NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter
                       = new NorthwindDataSetTableAdapters.CustomersTableAdapter();
                    NorthwindDataSet northwindDataSet = new NorthwindDataSet();
                    customersTableAdapter.Fill(northwindDataSet.Customers);

                    new NorthwindDataSetTableAdapters.ProductsTableAdapter().Fill(northwindDataSet.Products);
                     ///修改(增删改)SQL 服务器的Customers表
                    NorthWindSyncAgent syncAgent = new NorthWindSyncAgent(DataSvc);
                    Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
                    Debug.WriteLine(syncStats.TotalChangesDownloaded);

                     ///此时客户端的数据已经同步
                    customersTableAdapter.Fill(northwindDataSet.Customers);
                    new NorthwindDataSetTableAdapters.customersTableAdapter().Fill(northwindDataSet.Customers);
      new NorthwindDataSetTableAdapters.ProductsTableAdapter().Fill(northwindDataSet.Products);
                 }

    总结

    以上可见,通过IDE可以快速的建立一个常用的Sync程序,这个默认的程序只能下载,如果需要双向的同步可参考SDK:

    Walkthrough: Extending the Local Database Cache to Support Bidirectional Synchronization

  • 相关阅读:
    大数据内存模型(二级指针)
    多线程函数指针
    返回函数指针的函数
    动态分配二维数组指针
    俄罗斯方块学习笔记
    tailf
    tail
    cut
    split
    paste
  • 原文地址:https://www.cnblogs.com/2018/p/1961658.html
Copyright © 2020-2023  润新知