Tracking changes removed, zeroing table anchors does not work, ideas?

I have a desktop client that uses a synchronization infrastructure to synchronize a database with a server. Sometimes I experience problems with the "Cleanup" of table change tracking.

I did some research and found a message on the Internet that yielded some code that drops anchors in a table and then resyncs. This is intended to force the table to reload, thereby exacerbating the problem. (Source here)

I implemented the following code:

= On Synchronization :: =

catch (SyncException ex)
            {
                Exception ex2 = ex.InnerException;
                if (ex2.Message.Contains("cleaned up"))
                {
                    try
                    {
                        syncStats = syncAgent.Synchronize(true); 
                        //pass in true so removes anchors
                    catch (Exception anothererror)
                    {
                        //This will hit with another error equaling "Cleaned-up" on a table.
                    }
                }

= Sync Agent :: =

public SyncStatistics Synchronize(bool reinit)
        {
            if (!reinit)
                return base.Synchronize();
            try
            {
                ClientSyncProvider sqlCeProvider;
                sqlCeProvider = (ClientSyncProvider)this.LocalProvider;

                foreach (SyncTable st in this.Configuration.SyncTables)
                {
                    if (st.SyncDirection != SyncDirection.Snapshot)
                    {
                        // Null anchors here
                        sqlCeProvider.SetTableReceivedAnchor(st.TableName, new SyncAnchor());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return base.Synchronize();
        }

"", Synchronize (true) null , . , , , "catch (ex anothererror) {" "" .

, ?

, .

+3
1

. @sync_initialized SQL-?

, , @last_recieved_anchor CHANGE_TRACKING_MIN_VALID_VERSION.

:

IF @sync_initialized = 0
BEGIN 
//SELECT without limitation by the changetable.
END 
ELSE
BEGIN
//SELECT limited by the changetable.
IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(N'[WorkOrder]')) > @sync_last_received_anchor RAISERROR (N'SQL Server Change Tracking has cleaned up tracking information for table ''%s''. To recover from this error, the client must reinitialize its local database and try again',16,3,N'[WorkORder]')
END
0

Source: https://habr.com/ru/post/1724761/


All Articles