locked
SelectIncrementalDeletesCommand RRS feed

  • Question

  • Hello, I'm using Sync Services and am wondering why the SelectIncrementalDeletesCommand returns a DataTable with a null row in it when a row has been deleted on the server. the command states 'select *' from the change tracking table. When I execute this same command in SQL Studio, I get values for the table.
    This is an issue b/c I want to remove an entity from a list whenever one is deleted. Currently my solution is to get all entities when a delete happens, because I do not know which entity to delete. If the DataRow contained the information that I get from SQL Studio (Id) I would know which to delete.

    Thank you,

    UPDATE: By "returns a DataTable" I am refering to the SyncContext.DataSet that is returned. or the SyncTableProgress.DataTable.
    • Moved by Max Wang_1983 Thursday, April 21, 2011 11:40 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Wednesday, May 20, 2009 11:35 PM

Answers

  • I was able to get the ID of my entity by doing the following:
    if (row.RowState == DataRowState.Deleted)
    {
        Guid id = (Guid)row[IdColumnName, DataRowVersion.Original];
        //Remove from collection
    }

    I then could delete the entity from the collection by using the id.
    • Marked as answer by skendrotMVP Tuesday, September 1, 2009 9:57 PM
    Tuesday, September 1, 2009 9:57 PM

All replies

  • Do you mean that the entire row is null in the DataSet or only the non-PK columns?  Could you provide your SelectIncrementalDeletesCommand?

    Thanks,
    Phil
    Tuesday, May 26, 2009 4:28 PM
  • Phil,

    The entire row is null. Every column of the row has a null value.

    Here is my command:
    IF @sync_initialized > 0  BEGIN Select  *  FROM CHANGETABLE(CHANGES Task, @sync_last_received_anchor) CT  WHERE (CT.SYS_CHANGE_OPERATION = 'D' AND CT.SYS_CHANGE_VERSION <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CONTEXT IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary)); IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(@sync_table_name)) > @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,@sync_table_name)   END


    Thank you,
    Wednesday, May 27, 2009 8:31 PM
  • Could you try running this portion of the query in SSMS:

    Select  *  FROM CHANGETABLE(CHANGES Task, @sync_last_received_anchor) CT  WHERE (CT.SYS_CHANGE_OPERATION = 'D' AND CT.SYS_CHANGE_VERSION <= @sync_new_received_anchor AND (CT.SYS_CHANGE_CONTEXT IS NULL OR CT.SYS_CHANGE_CONTEXT <> @sync_client_id_binary))

    What is output from that?  Typically you don't want to do a Select *, but rather just the PK columns from the change table.

    Thanks-
    Phil
    Wednesday, May 27, 2009 10:02 PM
  • Phil,

    The row is still empty. When I am debugging, I can open the DataTable in the VS DataSet Visualilzer. Each column of the row contains (!) on the right side.
    If I try to access a column from the row i get a DeletedRowInaccessibleException, with the message "Deleted row information cannot be accessed through the row."

    Thanks,
    Wednesday, May 27, 2009 10:47 PM
  • Anyone have any ideas why these rows (System.Data.DataRow) would have null values?
    Friday, June 5, 2009 9:03 PM
  • I was able to get the ID of my entity by doing the following:
    if (row.RowState == DataRowState.Deleted)
    {
        Guid id = (Guid)row[IdColumnName, DataRowVersion.Original];
        //Remove from collection
    }

    I then could delete the entity from the collection by using the id.
    • Marked as answer by skendrotMVP Tuesday, September 1, 2009 9:57 PM
    Tuesday, September 1, 2009 9:57 PM