locked
How to Find changed records RRS feed

  • Question

  • In Sync services   i am able  to get the updated data using below code. How to find which rows are updated with the synchronization.

    If i have total records 10 out of that i have updated only one row in the database. While merging data using sync services how to find that row.

    Please help.

    ObjectQuery<FHMSummary> fhmSummary = _contextFhmEntities.FHMSummaries;

    bindingSource1.DataSource = fhmSummary.Execute(MergeOption.OverwriteChanges);

    Regards
    Madhusudhana Reddy
    Friday, December 24, 2010 7:23 AM

Answers

  • Hi Jin,

    Thank you very much.

    I tried with your sugesstion. It is working with "ChangesApplied" event. We need to insert below steps in "ChangesApplied" event.

    Below thread is helpful.

    http://social.microsoft.com/Forums/en/syncdevdiscussions/thread/6908324d-dbb3-4493-b1ed-8632c5cc90c2

                FhmServiceReference.FHMCacheSyncContractClient ts = new FHMCacheSyncContractClient();

                SyncContext sc = ts.GetChanges(e.GroupMetadata, e.Session);

                MessageBox.Show(sc.DataSet.Tables.Count.ToString()); 

                MessageBox.Show("ChangesApplied");

                //We look for every table in the scope

                for (int i = 0; i < sc.DataSet.Tables.Count; i++)

                {

                    var dataTable = sc.DataSet.Tables[i];

                    for (int j = 0; j < dataTable.Rows.Count; j++)

                    {

                        DataRow row = dataTable.Rows[j];

                        if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)

                        {

                            //If we are updating or deleting, we remove the row.

                            dataTable.Rows.Remove(dataTable.Rows[j]);

                        }

                    }

                }

    • Marked as answer by Madhu Nadamala Thursday, January 6, 2011 12:22 PM
    Thursday, January 6, 2011 12:20 PM

All replies

  • Hi,

    Which sync services / Sync framework version are you using?

    Thanks.

    Wednesday, December 29, 2010 8:47 PM
    Answerer
  • I am using Sync Frame work 2.1

    Monday, January 3, 2011 8:23 AM
  • Please consider event hanlders for the sync provider.

    For example, if you are using SqlSyncProvider, you could use ChangesApplied event handler to find out what has been changed.

    http://msdn.microsoft.com/en-us/library/microsoft.synchronization.data.sqlserver.sqlsyncprovider_events(SQL.105).aspx 

    If you are using DbServerSyncProvider, the similar topic can be found at http://msdn.microsoft.com/en-us/library/bb726009.aspx.

    Tuesday, January 4, 2011 6:25 PM
    Answerer
  • Hi Jin,

    Thank you very much.

    I tried with your sugesstion. It is working with "ChangesApplied" event. We need to insert below steps in "ChangesApplied" event.

    Below thread is helpful.

    http://social.microsoft.com/Forums/en/syncdevdiscussions/thread/6908324d-dbb3-4493-b1ed-8632c5cc90c2

                FhmServiceReference.FHMCacheSyncContractClient ts = new FHMCacheSyncContractClient();

                SyncContext sc = ts.GetChanges(e.GroupMetadata, e.Session);

                MessageBox.Show(sc.DataSet.Tables.Count.ToString()); 

                MessageBox.Show("ChangesApplied");

                //We look for every table in the scope

                for (int i = 0; i < sc.DataSet.Tables.Count; i++)

                {

                    var dataTable = sc.DataSet.Tables[i];

                    for (int j = 0; j < dataTable.Rows.Count; j++)

                    {

                        DataRow row = dataTable.Rows[j];

                        if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)

                        {

                            //If we are updating or deleting, we remove the row.

                            dataTable.Rows.Remove(dataTable.Rows[j]);

                        }

                    }

                }

    • Marked as answer by Madhu Nadamala Thursday, January 6, 2011 12:22 PM
    Thursday, January 6, 2011 12:20 PM
  • Hi jin,

     

    I am unable to get changes using below code,i set a breakpoint inside ClientChangesSelected, ServerChangesSelected,events are not firing, if any thing i missedout,please help me.

     

     private void button2_Click(object sender, EventArgs e)
            {
                //Open Server Connection Here
                using (SqlConnection oServConn = new SqlConnection(sSourceConnString))
                {
                    //Open Client Connection
                    using (SqlConnection oClientConn = new SqlConnection(sTargetConnString))
                    {
                        //Begin Synchronizing Data between the Client Scope and Server Scope via an Orchestrator Task
                        SyncOrchestrator oOrchestrator = new SyncOrchestrator
                        {
                            LocalProvider = new SqlSyncProvider("oSyncScope", oClientConn),

                            RemoteProvider = new SqlSyncProvider("oSyncScope", oServConn),
                            //Direction = SyncDirectionOrder.UploadAndDownload,
                           

                        };

                        ((SqlSyncProvider)oOrchestrator.LocalProvider).ChangesSelected += new EventHandler<DbChangesSelectedEventArgs>(ClientChangesSelected);
                      
                        ((SqlSyncProvider)oOrchestrator.RemoteProvider).ChangesSelected += new EventHandler<DbChangesSelectedEventArgs>(ServerChangesSelected);
                        //dataGridView1.DataSource = dtClient;
                        oOrchestrator.Direction = SyncDirectionOrder.Upload;
                        SyncOperationStatistics syncStats = oOrchestrator.Synchronize();
                       
                        //dataGridView1.DataSource = dtServer;
                        oOrchestrator.Direction = SyncDirectionOrder.Download;
                        SyncOperationStatistics syncStats1 = oOrchestrator.Synchronize();
                        // print statistics
                        //MessageBox.Show("Start Time: " + syncStats.SyncStartTime);
                        //MessageBox.Show("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
                        //MessageBox.Show("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
                        //MessageBox.Show("Complete Time: " + syncStats.SyncEndTime);
                        //MessageBox.Show(String.Empty);


                    }
                  
                }
                MessageBox.Show("Synchronization Complete");
            }

            static void ClientChangesSelected(object sender, DbChangesSelectedEventArgs e)
            {
               

                for (int i = 0; i < e.Context.DataSet.Tables.Count; i++)
                {
                    var dataTable = e.Context.DataSet.Tables[i];
                    for (int j = 0; j < dataTable.Rows.Count; j++)
                    {
                        DataRow row = dataTable.Rows[j];
                        if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)
                        {
                            //If we are updating or deleting, we remove the row.
                            dataTable.Rows.Remove(dataTable.Rows[j]);
                        }


                    }

                }
            }
            static void ServerChangesSelected(object sender, DbChangesSelectedEventArgs e)
            {

                for (int i = 0; i < e.Context.DataSet.Tables.Count; i++)
                {
                    var dataTable = e.Context.DataSet.Tables[i];
                    for (int j = 0; j < dataTable.Rows.Count; j++)
                    {
                        DataRow row = dataTable.Rows[j];
                        if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Deleted)
                        {
                            //If we are updating or deleting, we remove the row.
                            dataTable.Rows.Remove(dataTable.Rows[j]);
                        }


                    }

                }
            }

    Thursday, July 7, 2011 7:04 AM