Hi Mike,
I am admittedly no expert in SQL2005 websync so I would encourage you to
forward your new problem to the SQL2005 replication newsgroup. That said, the
following tricks may help you troubleshoot further:
1) Instead of chaining your call directly to the Synchronize() method from
the subscription object (i.e. mPullSub.SynchronizationAgent.Synchronize()),
you may want to save off a reference to the (Merge)SynchronizationAgent in a
variable and then hook up the Status event handler with something like this:
MergeSynchronizationAgent syncAgent = mPullSub.SynchronizationAgent
syncAgent.ExchangeType = MergeExchangeType.BiDirectional
syncAgent.Status += new AgentCore.StatusEventHandler(yourStatusEventHandler);
syncAgent.Syncrhonize();
(Warning: the snippet above will not compile)
2) Use SQL Profiler to trace the calls from the merge agent and see if
publisher\publisherdb\publication\subscriber\subscriberdb names are what you
expect them to be.
-Raymond
[quoted text, click to view] "msmith" wrote:
> Actually, it wasn't on the Main thread, that's fixed, now it says "The
> subscription to publication 'MTSMaster' has expired or does not exist."
>
> Code:
>
> public bool ReplSyncWin(bool init)
> {
> pubDB = replMasterPublisherDb;
> //public Form1()
> //{
> //InitializeComponent();
> //}
>
> //private void button1_Click(object sender, EventArgs e)
>
> //{
> //Cursor.Current = Cursors.WaitCursor;
> if (_synchronizeMergePullSubscription())
> {
> MobileTech.Core.Configuration.AppStart = false;
> return true;
> }
> else
> {
> return false;
> }
>
> }
> private bool _synchronizeMergePullSubscription()
> {
> try
> {
> //localConn = "Server=localhost;Integrated
> Security=True;Database=C:\\ROUTENET\\MobileTech.UI.WinCE\\DatabaseMobileTech.sdf";
> //subscriberSQLConn = new SqlConnection(localConn);
> //subscriberSQLConn.Open();
> subscriberConn = new ServerConnection(subServer);
>
> subscriberConn.Connect();
> MergePullSubscription mPullSub = new MergePullSubscription();
> mPullSub.ConnectionContext = subscriberConn;
> mPullSub.DatabaseName = subDB;
> mPullSub.PublisherName = replMasterPublisher;
> mPullSub.PublicationDBName = pubDB;
> mPullSub.PublicationName = replMasterPublication;
> //mPullSub.InternetLogin = replInternetLogin;
> //mPullSub.InternetPassword = replInternetPassword;
> //mPullSub.InternetSecurityMode =
> AuthenticationMethod.WindowsAuthentication;
> //mPullSub.InternetUrl = replInternetUrl;
> ////mPullSub.PublisherSecurity =
> AuthenticationMethod.WindowsAuthentication;
> //mPullSub.UseWebSynchronization = true;
> // if pull subscription exists, start the sync
>
> if (mPullSub.LoadProperties())
>
> {
> mPullSub.SynchronizationAgent.ExchangeType =
> MergeExchangeType.Bidirectional;
> mPullSub.SynchronizationAgent.Synchronize();
> }
> else
> {
> subscriberConn.Disconnect();
> // create the pull subscription and retry
>
> if (_createMergePullSubscription())
>
> _synchronizeMergePullSubscription();
>
> }
> }
> catch (Exception ex)
> {
> //MessageBox.Show(ex.ToString() + " " + ex.Message);
> return false;
> }
> finally
> {
> subscriberConn.Disconnect();
>
> //Cursor.Current = Cursors.Default;
> }
> return true;
> }
>
> private bool _createMergePullSubscription()
> {
>
> bool retVal = false;
>
> // To create a pull subscription, you need a connection to the
> Subscriber
> //and Publisher.
>
> //subscriberSQLConn = new SqlConnection(localConn);
> //subscriberSQLConn.Open();
> subscriberConn = new ServerConnection(subServer);
>
> //publisherSQLConn = new SqlConnection(localConn);
> //publisherSQLConn.
> //publisherSQLConn.Open();
> publisherConn = new
> ServerConnection("10.0.0.49");//publisherSQLConn);
>
> try
>
> {
>
> subscriberConn.Connect();
> publisherConn.Connect();
>
> // Register a new Subscriber at the Publisher, unless it is
> already
> //registered.
>
> RegisteredSubscriber subscriber;
>
> subscriber = new RegisteredSubscriber(subServer,
> publisherConn);
>
> if (!subscriber.IsExistingObject)
> {
> subscriber.Create();
> subscriber.Refresh();
> }
>
> MergePublication mergePublication = new MergePublication();
> mergePublication.Name = replMasterPublication;
> mergePublication.DatabaseName = pubDB;
> mergePublication.ConnectionContext = publisherConn;
>
> // If the publication exists, define the subscription at the
> Subscriber.
>
> if (mergePublication.LoadProperties())
> {
>
> // If the publication does not support pull
> subscriptions, allow them.
>
> // You must do this bitwise because
> Publication.Attributes is really a
> //bitmask.
>
> if ((mergePublication.Attributes &
> PublicationAttributes.AllowPull) == 0)
>
> {
> mergePublication.Attributes =
> mergePublication.Attributes |
> PublicationAttributes.AllowPull;
> mergePublication.CommitPropertyChanges();
> mergePublication.Refresh();
> }
>
> MergePullSubscription mergePullSubscription = new
> MergePullSubscription();
> // Define pull subscription properties.
> mergePullSubscription.ConnectionContext = subscriberConn;
> mergePullSubscription.DatabaseName = subDB;