3

我有一個桌面客戶端使用同步框架將數據庫同步到服務器。我偶爾會遇到問題「清理」表更改跟蹤。清理變更跟蹤,歸零表錨點不工作,想法?

我做了一些研究,並在互聯網上發現一篇文章,其中提供了一些重置表上錨點然後重新同步的代碼。這是爲了讓表格重新下載,從而解決問題。 (Source here)

我實現的代碼如下所示:

=在同步:: =

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){」與另一個「清理」異常。

任何想法,我錯了嗎?

謝謝, Kohan。

+0

「問題」?這些問題是否有錯誤編號或錯誤信息?在解決問題時,您不認爲錯誤消息的文本與某些方面相關嗎? – 2009-12-04 22:40:35

+1

的syncexception消息是「SQL服務器更改跟蹤清理了爲客戶表跟蹤信息。 從錯誤中恢復,客戶端必須重新初始化其本地數據庫,然後再試一次」 我的「問題」,直接關係到本作它會導致同步失敗,任何能夠幫助的人都應該確切知道我所指的是什麼。 我遵循帖子的說明,我希望它能解決我的「問題」,唉,這是不是這種情況,我只是問,如果有人可以看到爲什麼... – 4imble 2009-12-06 14:45:48

回答

0

問題可能出在適配器上。你在你的SQL命令中檢查@sync_initialized嗎?

如果您在增量命令中未區分已初始化和未初始化的同步,則會出現此錯誤,因爲它們將始終執行@last_recieved_anchorCHANGE_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

檢查@ sync_initialized沒有幫助在我的情況。使用由SqlSyncAdapterBuilder創建的包含@ sync_initialized檢查的默認查詢。 – Brent 2014-03-13 18:48:24