MS Sync Framework INSERT Trigger RRS feed

  • Question

  • Hello,

    Due to the sync framework insert trigger my business logic was broke. I was getting resulted in a StaleStateException (-1 rows affected, expected 1). error. I looked at the sync insert trigger and found a strange thing.

    There is an update call before inserting to the tracking table. This update call joins with the tracking table for inserted record. How it is going update the record which really do not exists! I removed the UPDATE call and it works fine now.

    However I am not sure the reason behind the presence of the UPDATE call withing the INSERT trigger.

    Here is the sample trigger:


    UPDATE [side] SET [sync_row_is_tombstone] = 0, [local_update_peer_key] = 0, [restore_timestamp] = NULL, [update_scope_local_id] = NULL, [last_change_datetime] = GETDATE(), [ID] = [i].[ID] FROM [sync].[MYTABLE_tracking] [side] JOIN INSERTED [i] ON [side].[PrimaryKey1] = [i].[PrimaryKey1] AND [side].[PrimaryKey2] = [i].[PrimaryKey2]

    INSERT INTO [sync].[MYTABLE_tracking] ([i].[PrimaryKey1], [i].[PrimaryKey2], [create_scope_local_id], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime], [restore_timestamp], [i].[ID]) SELECT [i].[PrimaryKey1], [i].[PrimaryKey2], NULL, 0, @@DBTS+1, NULL, 0, 0, GETDATE(), NULL, [i].[ID] FROM INSERTED [i] LEFT JOIN [sync].[MYTABLE_tracking] [side] ON [side].[PrimaryKey1] = [i].[PrimaryKey1] AND [side].[PrimaryKey2] = [i].[PrimaryKey2] WHERE [side].[PrimaryKey1] IS NULL AND [side].[PrimaryKey2] IS NULL

    Please let me know if anybody come across this situation and have better workaround.
    • Moved by Edwer Fang Tuesday, September 21, 2010 5:10 AM (From:.NET Framework Setup)
    Tuesday, September 14, 2010 9:27 AM

All replies

  • Hello,

    I think you may post this issue on Microsoft Sync Framework Forums(http://social.microsoft.com/Forums/en-US/category/sync) so you can get better and quicker response which makes answer searching in the fourm eaiser and be beneficial to other community members.

    Thanks for your understanding.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Wednesday, September 15, 2010 5:02 AM