locked
Will this design work? RRS feed

  • Question

  • I use  ‘SqlExpressClientSyncProvider’ to snapshot 7  tables in a n-tier WCF hub & spoke  application .

    I want the  Sync to be inside one transaction, and I can't use TruncateExistingOrCreateNewTable  because CreateSchema is not implemented.

    How about this ?

    1. set receivedanchor to null for affected fields A, B, C
    2. modify applychanges() method, like this 

     
         public override SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
            {
    
    
    [truncate table A, B, C in the client]           
    
    
     
                foreach (SyncTableMetadata metaTable in groupMetadata.TablesMetadata)
                {
                    SyncAnchor temp = metaTable.LastReceivedAnchor;
                    metaTable.LastReceivedAnchor = metaTable.LastSentAnchor;
                    metaTable.LastSentAnchor = temp;
                }
    • Moved by Hengzhe Li Friday, April 22, 2011 2:05 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, August 10, 2009 6:09 PM

Answers

  • OK - I think I answered my own question. I changed ApplyChanges to add a nested transaction . The finally block will unwind the reference count and let the commit occur.
     

            public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
            {
    
                string queryStr = "delete from tablea;delete from    tableb;delete from     tablec;";
                IDbCommand truncateCom = new SqlCommand(queryStr);
                truncateCom.Connection = _dbSyncProvider.Connection;
                truncateCom.CommandType = CommandType.Text;
                truncateCom.Transaction = _transaction;
    
    
                bool commandPassed = false;
                try
                {
                    BeginTransaction(null);
                    truncateCom.ExecuteNonQuery();
                    commandPassed = true;
    
    
    
                //Map SyncDirection from client POV to our internal server POV
    
                foreach (SyncTableMetadata tableMetadata in groupMetadata.TablesMetadata)
                {
    
                    if (tableMetadata.SyncDirection == SyncDirection.DownloadOnly || tableMetadata.SyncDirection == SyncDirection.Snapshot)
                    {
    
                        //This SyncDirection DownloadOnly/Snapshot is from a Client point of view. But our client is inturn a Server provider.   Hence switch this to UploadOnly
    
                        tableMetadata.SyncDirection = SyncDirection.UploadOnly;
    
                    }
    
                    else if (tableMetadata.SyncDirection == SyncDirection.UploadOnly)
                    {
    
                        //This SyncDirection UploadOnly is from Client POV. But our client is inturn a Server provider. Hence switch this to DownloadOnly
    
                        tableMetadata.SyncDirection = SyncDirection.DownloadOnly;
    
                    }
    
                }
    
                SyncContext syncContext = _dbSyncProvider.ApplyChanges(groupMetadata, dataSet, syncSession);
    
                foreach (SyncTableMetadata table in groupMetadata.TablesMetadata)
                {
    
                    SetTableReceivedAnchor(table.TableName, groupMetadata.NewAnchor);
    
                }
    
                return syncContext;
    
                }
                finally
                {
                    truncateCom.Dispose();
                    EndTransaction(commandPassed, null);
                }
    
            }
    Tuesday, August 11, 2009 4:45 PM