locked
How to Transaction.Rollback() when connection lost? (SyncService ADO.NET and WCF) RRS feed

  • Question

  • Hello,

    I have made a n-tier synchronisation with Sync Services for ADO.NET and a WCF-Service.

    Now I want to rollback a transaction if the WCF-Service lost the connection (networkproblems for example).


    1. How can I get the information to SyncFramework that I have lost my connection?

    In the ApplyChangedEvent I have just access to the database connection, or?
    For example:
    void ApplyChangeFailed(object sender, ApplyChangeFailedEventArgs e)
    
     {
    
    if (e.Connection.State == ConnectionState.Broken || e.Connection.State == ConnectionState.Closed)
     {
    
    e.Transaction.Rollback();
    throw  new Exception(e.Conflict.ErrorMessage);
    
      }
    
     }
    This event raised if I lost connection to the database and not raised if the Service lost his networkconnection, or?


    2. I am using the batchmodus to synchronize. Does SyncFramework use one transaction for all batches or one transaction for one batch?
        All my SyncTables are in one SyncGroup.


    best regards


    Boris Huelsmann
    • Edited by Boris.Huelsmann Monday, April 27, 2009 6:50 AM
    • Moved by Hengzhe Li Friday, April 22, 2011 3:22 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Friday, April 24, 2009 9:48 AM

Answers

  • Hi Boris,

    All changes in a syncgroup are applied to the server database in one transaction. I believe you are using batching only for download so all changes for upload are in one batch. I am assuming that you are asking about connection between client and wcf service. The applychangefailed event is only fired on sync failures not on wcf client side timeouts. You will need to setup some communication between the wcf service and the thread running sync to abort the sync when client goes away.

    thanks
    Sudarshan


    Development Lead , Microsoft
    Wednesday, April 29, 2009 10:51 PM
    Moderator