0

I have a database which have multiple tables but these tables have not any relationship define(Referential integrity) in database. They are related to each other but maintained by trigger and application. I have created custom conflict resolver on Microsoft SQL server 2008 R2 merge replication. In custom conflict resolver, I am checking subscribers priority by SQL query from publisher database and based on that priority. I am resolving the conflict in replication data-table.

Custom Conflict Resolver Code as below

public override ActionOnUpdateConflict UpdateConflictsHandler(DataSet publisherDataSet, DataSet subscriberDataSet, ref DataSet customDataSet,
        ref ConflictLogType conflictLogType, ref string customConflictMessage, ref int historyLogLevel, ref string historyLogMessage)
{
    // Priority column AcceptDate
    DateTime? publisherModifiedDate = string.IsNullOrWhiteSpace(Convert.ToString(publisherDataSet.Tables[0].Rows[0]["AcceptDate"])) ? new Nullable<DateTime>() : DateTime.Parse(publisherDataSet.Tables[0].Rows[0]["AcceptDate"].ToString());
    DateTime? subscriberModifiedDate = string.IsNullOrWhiteSpace(Convert.ToString(subscriberDataSet.Tables[0].Rows[0]["AcceptDate"])) ? new Nullable<DateTime>() : DateTime.Parse(subscriberDataSet.Tables[0].Rows[0]["AcceptDate"].ToString());

    //Get priority via userid
    int publisherUserId = Convert.ToInt32(publisherDataSet.Tables[0].Rows[0]["UserId"]);
    int subcriberUserId = Convert.ToInt32(subscriberDataSet.Tables[0].Rows[0]["UserId"]);

    DataTable dt = new DataTable();
    //Publisher
    using (SqlConnection sqlConnection = new SqlConnection(AppConfig.PubliosherConnectionString))
    {
        SqlCommand cmd = new SqlCommand("select * from RISubscriber where UserId=" + publisherUserId, sqlConnection);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
    }


    int publisherPriority = Convert.ToInt32(dt.Rows[0]["SubscriberPriority"]);
    //Subcriber
    dt = new DataTable();
    using (SqlConnection sqlConnection = new SqlConnection(AppConfig.PubliosherConnectionString))
    {
        SqlCommand cmd = new SqlCommand("select * from RISubscriber where UserId=" + subcriberUserId, sqlConnection);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
    }

    int subcriberPriority = Convert.ToInt32(dt.Rows[0]["SubscriberPriority"]);

    if (subcriberPriority > publisherPriority)
    {
        customDataSet = subscriberDataSet.Copy();
    }
    else
    {
        customDataSet = publisherDataSet.Copy();
    }
    return ActionOnUpdateConflict.AcceptCustomConflictData;
}

Question: I want to replicate the data between subscribers based on custom conflict resolver and want to maintain the data integrity between tables.

Please let me know. If you have any idea.

How we can do it?

Thank you

Deepak Joshi
  • 1,036
  • 7
  • 17
  • 1
    Can you elaborate on how your custom conflict resolver works? I would expect this will make a difference to the answer. – David Rushton Dec 30 '15 at 13:54
  • In custom conflict resolver, I am checking subscribers priority by SQL query from publisher database and based on that priority I am resolving the conflict in replication. – Deepak Joshi Jan 04 '16 at 10:25

0 Answers0