Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

RMO Synchronize subscription

From Wiki

Jump to: navigation, search

Use this base method to start synchronizing replication from publisher to subscriber. This is extremely useful when the subscriber is SQLExpress or other sources that do not utilize the SQL Agent.

  1. string publicationName = <publication name>;
  2.             string publisherName = <publication instance>;
  3.             string subscriberName = <subscription instance>;
  4.             string subscriptionDbName = <subscription database name>;
  5.             string publicationDbName = <publication database;
  6.            
  7.             ServerConnection conn = new ServerConnection(subscriberName);
  8.             ServerConnection publisherConn = new ServerConnection(publisherName);
  9.          
  10.             MergePullSubscription subscription;
  11.  
  12.             try
  13.             {
  14.                 conn.Connect();
  15.                 publisherConn.Connect();
  16.  
  17.                 subscription = new MergePullSubscription();
  18.                
  19.                 subscription.ConnectionContext = conn;
  20.                 subscription.PublisherSecurity.SecurityMode = ReplicationSecurityMode.SqlStandard;
  21.                 subscription.DistributorSecurity.WindowsAuthentication = false;
  22.  
  23.                 subscription.DatabaseName = subscriptionDbName;
  24.                 subscription.PublisherName = publisherName;
  25.                 subscription.PublicationDBName = publicationDbName;
  26.                 subscription.PublicationName = publicationName;
  27.  
  28.                 if (subscription.LoadProperties())
  29.                 {
  30.                     if (subscription.PublisherSecurity != null || subscription.DistributorSecurity != null)
  31.                     {
  32.                         subscription.SynchronizationAgent.Synchronize();
  33.                     }
  34.                     else
  35.                     {
  36.                         throw new ApplicationException("There is insufficent metadata to " +
  37.                             "synchronize the subscription. Recreate the subscription with " +
  38.                             "the agent job or supply the required agent properties at run time.");
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     throw new ApplicationException(String.Format(
  44.                         "A subscription to '{0}' does not exist on {1}",
  45.                         publicationName, subscriberName));
  46.                 }
  47.             }
  48.             catch (Exception ex)
  49.             {
  50.                 throw new ApplicationException("The subscription could not be " +
  51.                     "synchronized. Verify that the subscription has " +
  52.                     "been defined correctly.", ex);
  53.             }
  54.             finally
  55.             {
  56.                 conn.Disconnect();
  57.             }
  58.         }

--onpnt 01:23, 30 December 2010 (GMT)

813 Rating: 2.5/5 (24 votes cast)