locked
How do compare the value returned by CHANGE_TRACKING_MIN_VALID_VERSION to SyncAnchor returned by GetTableReceivedAnchor RRS feed

  • Question

  • Before executing a sync I want to check if the tables are valid by looping through each table and checking  as in this snippet:
    Dim
    last_received_anchor As SyncAnchor

    For Each st As SyncTable In Configuration.SyncTables

              last_received_anchor = localSyncProvider.GetTableReceivedAnchor(st.TableName)

              cmd.CommandText = "SELECT  CHANGE_TRACKING_MIN_VALID_VERSION(object_id('" & st.TableName & "'))"

              Dim rdr = cmd.ExecuteReader()

              If rdr.Read() Then

                        If rdr.GetInt64(0) last_received_anchor Then

                      localSyncProvider.SetTableReceivedAnchor(st.tableName, New SyncAnchor)

                       End If

              End If

              rdr.Close()

    Next

     

     

    How can I get a bigint value from a SyncAnchor to compare it to the int64 server value  returned by CHANGE_TRACKING_MIN_VALID_VERSION  ?

    • Moved by Max Wang_1983 Thursday, April 21, 2011 10:48 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, October 29, 2009 4:47 PM

Answers

  • I found the answer in a thread on this forum.  Here is a function I wrote which does it:

     

    Public Function AnchorToUInt64(ByVal last_received_anchor As Byte()) As UInt64

     

    Dim memStream As MemoryStream, formatter As New BinaryFormatter

    memStream =

    New MemoryStream(last_received_anchor)

     

    Return formatter.Deserialize(memStream)

     

    End Function

    • Marked as answer by PapaStoke Thursday, October 29, 2009 8:48 PM
    Thursday, October 29, 2009 8:48 PM

All replies

  • Hi,

    Please try BitConverter.ToInt64(SyncAnchor.Anchor).

    Thanks,
    Dong


    This posting is provided AS IS with no warranties, and confers no rights.
    Thursday, October 29, 2009 5:19 PM
    Moderator
  • SyncAnchor.Anchor is a byte array of 58 bytes.  Using BitConverter.ToInt64(SyncAnchor.Anchor,0) or BitConverter.ToUInt64(SyncAnchor.Anchor,0) results in either very large negative and positive numbers which are nowhere near the 13767 I receive from CHANGE_TRACKING_MIN_VALID_VERSION on the server.

    Do you know how the Change tracking value from SQL Server is being stored in SyncAnchor.Anchor ?
    • Marked as answer by PapaStoke Thursday, October 29, 2009 8:47 PM
    • Unmarked as answer by PapaStoke Thursday, October 29, 2009 8:47 PM
    Thursday, October 29, 2009 7:24 PM
  • I found the answer in a thread on this forum.  Here is a function I wrote which does it:

     

    Public Function AnchorToUInt64(ByVal last_received_anchor As Byte()) As UInt64

     

    Dim memStream As MemoryStream, formatter As New BinaryFormatter

    memStream =

    New MemoryStream(last_received_anchor)

     

    Return formatter.Deserialize(memStream)

     

    End Function

    • Marked as answer by PapaStoke Thursday, October 29, 2009 8:48 PM
    Thursday, October 29, 2009 8:48 PM
  • My mistake. The byte array contains type information as well. Please try the below code snippet:

    MemoryStream memStream = new MemoryStream(SyncAnchor.Anchor);
    BinaryFormatter formatter = new BinaryFormatter();
    Int64 val = (Int64) formatter.Deserialize(memStream);


    Thanks,
    Dong


    This posting is provided AS IS with no warranties, and confers no rights.
    Thursday, October 29, 2009 9:57 PM
    Moderator