3

我有一个桌面客户端,它使用同步框架将数据库同步到服务器。我偶尔会遇到问题“清理”表格更改跟踪。

我做了一些研究,并在互联网上找到了一个帖子,其中提供了一些代码,这些代码可以重置桌子上的锚点,然后重新同步。这是为了使表格重新下载,从而解决问题。(来源在这里)

我实现了这样的代码:

=同步时:: =

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.
                    }
                }

= 同步代理:: =

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) 并将每个表的所有锚定为空,然后调用另一个同步。这就是成功同步的重点,不幸的是,情况并非如此,并且会遇到另一个“已清理”异常的“catch (ex anothererror){”。

有什么想法我哪里出错了吗?

谢谢,科汉。

4

1 回答 1

0

问题可能出在适配器上。你检查@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
于 2009-12-21T15:31:13.203 回答