locked
Provide N TIER Application sample for sql server 2005 to sql sever 2005 express RRS feed

  • Question

  • please provide some sample with N TIER architecture for sql server 2005 to sql sever 2005 express.
    Currently MICROSOFT had given only samples for 2 tier architecture where serversyncprovider and clientsyncprovider reside at client itself.(this might not be used in real time)
    also, if we search the internetnet there are example for devices and they are using VS2008 local database cache or sql server change tracking



    Thanks, Bharathi
    • Moved by Max Wang_1983 Thursday, April 21, 2011 11:04 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, October 19, 2009 6:41 AM

Answers

  • You can find the sample code in the Sync Services for ADO.NET Documentation.

    For Offline scenario, I need to do 2 things for upgrading 2-tier to n-tier:

    1. Add a Web service that calls the server provider:

    public class ServiceForSync : IServiceForSync
    {
    
        private SampleServerSyncProvider _serverSyncProvider;
    
        public ServiceForSync()
        {
             this._serverSyncProvider = new SampleServerSyncProvider();
        }
        
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession) {
            return this._serverSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession);
        }
        
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) {
            return this._serverSyncProvider.GetChanges(groupMetadata, syncSession);
        }
        
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession) {
            return this._serverSyncProvider.GetSchema(tableNames, syncSession);
        }
        
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual SyncServerInfo GetServerInfo(SyncSession syncSession) {
            return this._serverSyncProvider.GetServerInfo(syncSession);
        }       
    }
    


    2. Add the service reference at client and replace the SyncAgent.RemoteProvider with the proxy:

    public class SyncServiceAgent : SyncAgent
    {
        public SyncServiceAgent()
        {
            ServiceForSyncClient serviceProxy = new ServiceForSyncClient();
            this.RemoteProvider = new ServerSyncProviderProxy(serviceProxy);

        // set this.LocalProvider for sql express...

        }
    }

    Sync Services will call RemoteProvider which implemented following interface (4 methods) - doesn't matter it is local call or Web service call:

    [ServiceContract]
    public interface IServiceForSync
    {
        [OperationContract()]
        SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession);
    
        [OperationContract()]
        SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    
        [OperationContract()]
        SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession);
    
        [OperationContract()]
        SyncServerInfo GetServerInfo(SyncSession syncSession);
    }
    
    Monday, October 19, 2009 10:28 PM