locked
Bidirectional sync not inserting rows on server database (updates work) RRS feed

  • Question

  • I am using SQL 2008 R2 on the server and SQL compact 3.5 sp1 on the client.

    We have a CoupledChangeTracking approach in place (we're not using the SQL change tracking feature)

    Most of the tables we are dealing with are set for a TableCreationOption of DropExistingOrCreateNewTable, and having a syncDirection of DownloadOnly (incremental changes from server down to client).

    We have a few tables that are set for TableCreationOption.UploadExistingOrCreateNewTable, and having a syncDirection or Bidirectional.

    The change tracking is configured to use two date columns in our tables (CreatedDate and LastUpdatedDate)

    The tables with the DownloadOnly syncDirection work perfectly fine.

    The problem we have are with tables that are set for Bidirectional sync.  Changes being made in the local tables, within the SQL compact SDF, are not propagating up to the server properly.  More specifically, NEW ROWS being created locally do not get inserted into the server copy of the table.  Using SQL management studio I have verified that the changes are happening properly in the local SDF. 

    Again NEW ROWS don't get inserted into the server table, but UPDATES to existing rows work fine (when the rows are already in both copies of the table, as verified by manually creating rows on the server table as a test)

    Using SQL profiler during the syncronization, I can see that it's trying to perform an UPDATE statement to modify existing rows.  Seems to me that this is where my trouble lies, since the rows are not yet on the server, it needs to be doing an insert rather than an update.

    Based on the above can somebody guide me on where else to look here?

    Thanks,

    Greg

     

     

    Tuesday, December 14, 2010 11:09 PM

All replies

  • did you hand code the provisioning of sync fx components?

    can you confirm in the client side if the inserts are being selected at all (chk the dataset on SelectedChanges)?

    Tuesday, December 14, 2010 11:21 PM
  • Thanks for the reply JuneT.

    Yes, everything is hand coded in the sense that I did not use the tooling within VS GUI to generate anything.

    Clearly my knowledge level of the sync framework is not as advanced as yours.  Would you be kind enough to describe in more detail, how I would go about checking if the inserts are being selected at all?  I don't see anything in MSDN documentation about there being a "SelectedChanges" event that I can handle, nor am I using datasets anywhere to my knowledge (maybe sync fx uses datasets under the covers?)


    Thanks,
    Greg

     

     

    Tuesday, December 14, 2010 11:37 PM
  • sorry, its ChangesSelected :) http://msdn.microsoft.com/en-us/library/microsoft.synchronization.data.sqlserverce.sqlceclientsyncprovider.changesselected.aspx

     yes, it's all Datasets under the hood for Sync Fx database sync.

    Wednesday, December 15, 2010 12:55 AM
  • Is there any valid reason why this event may not be firing?  I have it all set up but the event never fires.

      Private WithEvents instance As SqlCeClientSyncProvider
    
      Private Sub InitializeProviders()
    
        'Instantiate a client synchronization provider and specify it
        'as the local provider for this synchronization agent. <br/>
        'TE2DataClientSyncProvider inherits SqlCeClientSyncProvider.
    
        Me.LocalProvider = New TE2DataClientSyncProvider()
        instance = DirectCast(Me.LocalProvider, SqlCeClientSyncProvider) 'for the purpose of handling changes selected.
    
        'Instantiate a server synchronization provider and specify it
        'as the remote provider for this synchronization agent.
        Me.RemoteProvider = New TE2DataServerSyncProvider()
    
        'Instantiate a server synchronization provider and specify it
        'as the remote provider for this synchronization agent.
        DataProvider = New TE2DataServerSyncProvider()
        Me.RemoteProvider = DataProvider
    
      End Sub
    
      Private Sub ChangesSelectedHandler(ByVal sender As Object, ByVal args As ChangesSelectedEventArgs) Handles instance.ChangesSelected
        'I have a breakpoint on this method that never gets hit when I invoke the synchronization process
      End Sub
    

     

    Wednesday, December 15, 2010 4:53 PM
  • By the way the code in my last reply exists within my SyncAgent class.

    The constructor of the SyncAgent calls InitializeProviders...and the SyncAgent itself is constructed on app startup.  I put a breakpoint on InitializeProviders just to be sure it ran through the method and it does.

    Greg

     

    Wednesday, December 15, 2010 5:57 PM