locked
Getting the SyncSession.SyncNewReceivedAnchor RRS feed

  • Question

  • Hi All,

     

    I am trying to get the Sync New Received Anchor to be stored in my Server Side database. The Purpose is to store the Time Stamp in which we have received the data from the client. To achieve this we are using the following command:

     

            SqlCommand selectNewAnchorCommand = new SqlCommand();
            string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;
            selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = GETUTCDATE()";
            selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp);
            selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;
            selectNewAnchorCommand.Connection = serverConnection;
            this.serverProvider.SelectNewAnchorCommand = selectNewAnchorCommand;
    

    and once we receive th Anchor i am using it in the following way:

    sqlCmdTransactionMaster.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Timestamp);
    

    The Output should be "Current Date" but i am getting the following date

    "1753-01-01 12:00:00.000"

    This date is a default date available in SQL Server. 

    Environment :  Visual Studio 2008 , Sync Framework 2.1 & SQL Server 2008 (with Tracking False)

    Please let me know where i am going wrong in this:

     

    Thanks in Advance
    Biju Melayil

     

     

    Thursday, February 3, 2011 4:28 AM

Answers

  • am assuming sqlCmdTransactionMaster is your custom SQL Command. afaik, Sync Fx only injects the Sync Session parameters automatically on the sync fx related methods.

    if you're just after the last received anchor, on the ChangesApplied event, check out the Context in of the event argument. it has a property NewAnchor.

    or you can check out the LastReceivedAnchor and LastSentAnchor properties as well.

    • Marked as answer by Biju S Melayil Thursday, February 10, 2011 4:14 AM
    Tuesday, February 8, 2011 6:00 AM

All replies

  • In sqlCmdTransactionMaster, you declared a new parameter named @sync_new_received_anchor of type timestamp without defining a value for it, so the default value will be used.

    Thursday, February 3, 2011 11:59 PM
  • the sql db type for this command should be Datetime instead of the Timestamp.

    thanks

    Yunwen


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, February 4, 2011 3:32 AM
  • Hi Minh,

    Thanks for the Reply.
    I am setting  the Sync New Received Anchor before using it in the SqlCmdTransactionMaster.
    Please let me know how to use it then.

     

    Thanks Again
    Biju Melayil


    Regards Biju S Melayil
    Monday, February 7, 2011 5:04 AM
  • as mentioned by Yunwen, your select anchor command retrieves a Datetime via GetUtcDate whereas your parameter type is a Timestamp. The Timestamp data type in SQL Server has nothing to do with date nor time.
    Monday, February 7, 2011 12:28 PM
  • Hi June,

     

    I have changed the Code as per your instructions but i am getting the same Result.

     SqlCommand selectNewAnchorCommand = new SqlCommand();
        string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;
        selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = GETUTCDATE()";
        selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.DateTime);
        selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;
        selectNewAnchorCommand.Connection = serverConnection;
        this.serverProvider.SelectNewAnchorCommand = selectNewAnchorCommand;
    

    and once we receive th Anchor i am using it in the following way:

     

    sqlCmdTransactionMaster.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.DateTime);

    The Output i would require is that i want to store the Date & Time of the record received in the Server for future reference. is there any other way of getting this rather than using the NewAnchor Command

    Regards
    Biju


    Regards Biju S Melayil
    Tuesday, February 8, 2011 5:03 AM
  • am assuming sqlCmdTransactionMaster is your custom SQL Command. afaik, Sync Fx only injects the Sync Session parameters automatically on the sync fx related methods.

    if you're just after the last received anchor, on the ChangesApplied event, check out the Context in of the event argument. it has a property NewAnchor.

    or you can check out the LastReceivedAnchor and LastSentAnchor properties as well.

    • Marked as answer by Biju S Melayil Thursday, February 10, 2011 4:14 AM
    Tuesday, February 8, 2011 6:00 AM
  • Hi June,

    Thanks for the Info.

    The Main Intention of us was to get the Date & Time of the server when the record is inserted.
    Instead of going with this we have created a simple trigger which will update the date and time when the record is inserted.
    It has solved problem for the time being. But in case we require new received anchor for a bi directional sync then we will be looking into this option.

    Thanks for your Support

    Regards
    Biju


    Regards Biju S Melayil
    Thursday, February 10, 2011 4:13 AM