Groups | Blog | Home
all groups > sql server replication > june 2007 >

sql server replication : Upgrading Merge Replication technologies


Guy Thornton
6/12/2007 8:04:00 AM
Hilary,

I was wondering if you could lend your expertise to somewhat a newbie
question.

I am just now in the process of swithing my application / database
environment to sql server 2005.

I have an application environment that you have actually helped me with in
the past that includes an SQL Server 2000 server and MSDE clients. I have
merge replication setup in this environment, and within my application I have
been using the ActiveX objects to implement merge replication.

So for the conversion, I thought it was a good time for me to upgrade from
the ActiveX objects and use the .Net framework objects. The problem I'm
having is that there is so much information available that I am having a
problem understanding where to begin.

In my current application, I have my SQL Merge object and set the properties
for it and then call .AddSubscription with the db create database option.
afterwards I initialize and run the syncrhonization. This all works
wonderfully because if the subscriber is a new subscriber the merge object
knows to create the subscription on the server, create the local database and
apply the initial snapshot.

So my basic question is using the .net framework what is the overall process
Hilary Cotter
6/12/2007 10:12:17 PM
The activeX components which ship in SQL Server 2005 are highly symmetrical
with the ones which shipped in SQL 2000.

Do you need a .Net code sample?

Here is a c sharp one: Create a form add a button called Synchronize, a
progress bar and 4 labels called PublisherConflicts, PublisherChanges,
SubscriberConflicts and SubscriberChanges. Then create an interop to the
merge replication activeX control found in c:\Program files\Microsoft SQl
Server\90\com. It is called sqlmergx.dll

using System;
using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Runtime.InteropServices;

using SQLMERGXLib;



namespace MergeTest3

{

public partial class Form1 : Form

{

public event _SQLMergeEvents_StatusEventHandler StatusEventMerge;

public Form1()

{

InitializeComponent();

}

private void Synchronize_Click(object sender, System.EventArgs e)

{

Synchronzie_mergesub();

}

private void Synchronzie_mergesub()

{

SQLMergeClass objMerge = new SQLMergeClass();

objMerge.Publisher = System.Environment.MachineName.ToString();

objMerge.Publisher = Dns.GetHostName();

objMerge.PublisherDatabase = "AdventureWorks";

objMerge.Publication = "AdventureWorks";



objMerge.PublisherSecurityMode =
SQLMERGXLib.SECURITY_TYPE.NT_AUTHENTICATION;

objMerge.Subscriber = System.Environment.MachineName.ToString();

objMerge.SubscriberDatabase = "mergesub";

objMerge.AddSubscription(DBADDOPTION.REGISTER_SUBSCRIPTION,
SQLMERGXLib.SUBSCRIPTION_HOST.NONE);

objMerge.SubscriberSecurityMode =
SQLMERGXLib.SECURITY_TYPE.NT_AUTHENTICATION;

objMerge.Status += new _SQLMergeEvents_StatusEventHandler(objMerge_Status);

try

{

label1.Visible = true;

label1.Text = "Initializing Merge Sub";

label1.Refresh();

objMerge.Initialize();

objMerge.Run();

label1.Text = "Running Merge Agent";

label1.Refresh();

objMerge.Terminate();

label1.Text = "Merge Agent complete";

label1.Refresh();

}

catch (Exception e)

{

MessageBox.Show(e.StackTrace);

MessageBox.Show(e.Message);

}

PublisherConflicts.Text = "Publisher Conflicts: " +
objMerge.PublisherConflicts.ToString();

PublisherConflicts.Update();

PublisherChanges.Text = "Publisher Changes: " +
objMerge.PublisherChanges.ToString();

PublisherChanges.Update();

SubscriberConflicts.Text = "Subscriber Conflicts: " +
objMerge.SubscriberConflicts.ToString();

SubscriberConflicts.Update();

SubscriberChanges.Text = "Subscriber Changes: " +
objMerge.SubscriberChanges.ToString();

SubscriberChanges.Update();

}

public SQLMERGXLib.STATUS_RETURN_CODE objMerge_Status(string Message, int
Percent)

{

label1.Text = Message.ToString() + " " + Percent.ToString() + "% complete.";

label1.Update();

progressBar1.Value = Percent;

progressBar1.Update();

StatusEventMerge(Message, Percent);

return new SQLMERGXLib.STATUS_RETURN_CODE();

}

private void Form1_Load(object sender, EventArgs e)

{

}






}

}


--
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
[quoted text, click to view]

Guy Thornton
6/18/2007 6:03:02 AM
Hi Hilary,

Yes I seen the activeX controls that ship with SQL Server 2005 and was able
to very easily convert that code in my application.

I was however, attempting to do the same functionality using the
Microsoft.sqlserver.replication namespace classes and was wondering if you
had a code sample that uses these objects?


[quoted text, click to view]
AddThis Social Bookmark Button