Friday, March 23, 2012

How to Setup Merge replication with sql express

I have a Windows Mobile aplication that uses merge replication to synchronize between sql compact and full sql Enterprise edition and It works great. Instantiating the SqlCeReplication object setting it's properties and calling Synchronize on it is pretty simple assuming everything is setup properly at the publisher.

For the life of me I can't figure out how to do this on the desktop (Programatically setup a subscription and create a database using objects in the System.Replication Namespace and hopefully call Synchronize on it).

Someone please point me in the right direction.

Thanks,


Patrick

See topic "Programming with Replication Management Objects", http://msdn2.microsoft.com/en-us/library/ms146869(SQL.90).aspx.

|||

Look at the MergeSynchronizationAgent class.

Here is some sample code in C#:

Code Snippet

_mergeAgent = newMergeSynchronizationAgent();

_mergeAgent.Publication = _publication;

_mergeAgent.Publisher = _publisher;

_mergeAgent.PublisherDatabase = _publisherDB;

_mergeAgent.PublisherSecurityMode = SecurityMode.Integrated;

_mergeAgent.Distributor = _distributor;

_mergeAgent.DistributorLogin = _distributorLogin;

_mergeAgent.DistributorPassword = _distributorPassword;

_mergeAgent.DistributorSecurityMode = SecurityMode.Standard;

_mergeAgent.Subscriber = _subscriber;

_mergeAgent.SubscriberDatabase = _subscriberDB;

_mergeAgent.SubscriberLogin = _subscriberLogin;

_mergeAgent.SubscriberPassword = _subscriberPassword;

_mergeAgent.SubscriberSecurityMode = SecurityMode.Standard;

_mergeAgent.SubscriptionType = SubscriptionOption.Pull;

_mergeAgent.LoginTimeout = _LoginTimeOut;

_mergeAgent.QueryTimeout = _QueryTimeOut;

_mergeAgent.Synchronize();

Hope this helps!

No comments:

Post a Comment