Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 清理更改跟踪,清空表锚不工作,想法?_C#_Sql Server 2008_Synchronization_Microsoft Sync Framework - Fatal编程技术网

C# 清理更改跟踪,清空表锚不工作,想法?

C# 清理更改跟踪,清空表锚不工作,想法?,c#,sql-server-2008,synchronization,microsoft-sync-framework,C#,Sql Server 2008,Synchronization,Microsoft Sync Framework,我有一个桌面客户端,它使用同步框架将数据库同步到服务器。我偶尔在“清理”表更改跟踪时遇到问题 我做了一些研究,在互联网上找到了一篇文章,其中给出了一些代码,可以重置表上的锚,然后重新同步。这是为了使表重新下载,从而解决问题 我实现了如下代码: =同步时::= catch (SyncException ex) { Exception ex2 = ex.InnerException; if (ex2.Messag

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

我做了一些研究,在互联网上找到了一篇文章,其中给出了一些代码,可以重置表上的锚,然后重新同步。这是为了使表重新下载,从而解决问题

我实现了如下代码:

=同步时::=

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)和null每个表的所有锚,然后调用另一个同步。这就是它要成功同步的地方,不幸的是,情况并非如此,它将用另一个“已清理”异常命中“catch(ex-anothererror){”

你知道我哪里出错了吗

谢谢,
Kohan。

适配器可能有问题。是否在SQL命令中选中
@sync\u initialized

如果在增量命令中不区分已初始化和未初始化的同步,则会出现此错误,因为它们将始终在
@上次接收的\u锚定
更改跟踪\u最小\u有效版本
之间执行检查

我的增量插入命令遵循以下结构:

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

“问题”?这些问题是否有错误编号或错误消息?您不认为在故障排除时,错误消息的文本在某种程度上是相关的吗?syncexception消息是SQL Server更改跟踪已清理表客户端的跟踪信息。若要从此错误中恢复,客户端必须重新初始化其本地数据库,然后重试“我的”问题与此直接相关,因为它会导致同步失败,任何有能力提供帮助的人都应该确切知道我指的是什么。我遵循了我链接的帖子的说明,希望它能解决我的“问题”唉,事实并非如此,我只是想问是否有人能理解为什么…检查@sync_initialized对我的情况没有帮助。使用由SqlSyncAdapterBuilder创建的默认查询,其中包含@sync_initialized检查。