SQL 2005 and SQL Express VS2005 July CTP Merge Replication

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by bXNtaXR » Tue, 30 Aug 2005 11:55:03


When I execute
(MergePullSubscription)mPullSub.SynchronizationAgent.Synchronize() I get an
error {"The MergeSynchronizationAgent class must be instantiated on a
Single-Threaded Apartment (STA) thread."}, but as far as I can tell it is. I
even added the attribure [STAThread] and still get the error.

Thanks Mike Smith
 
 
 

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by Hilary Cot » Wed, 31 Aug 2005 00:55:42

did you post this to microsoft.private.sqlserver2005.replication?

--
Hilary Cotter
Looking for a SQL Server replication book?
http://www.yqcomputer.com/

Looking for a FAQ on Indexing Services/SQL FTS
http://www.yqcomputer.com/


an
I

 
 
 

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by UmF5bW9uZC » Wed, 31 Aug 2005 02:07:01

Hi Mike,

For the [STAThread] property to work, it must be used on the "first" method
of a thread. If you want to change the main thread of a process to be an
STAThread, you would have to decorate the Main method of the program with the
[STAThread] attribute. I am guessing that in your case, only the method
immediately wrapping the call to mPullSub.SynchronizationAgent is decorated
with the [STAThread] attribute. In any case, we can probably figure out
exactly what is going if you can post a few relevant code-snippets here.

HTH

-Ryamond
 
 
 

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by bXNtaXR » Wed, 31 Aug 2005 06:37:39

I did add the attribute to the Main method of the program.
There are no other Thread attributes anywhere else in the program.

Mike
 
 
 

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by bXNtaXR » Wed, 31 Aug 2005 07:11:03

ctually, 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 = n
 
 
 

SQL 2005 and SQL Express VS2005 July CTP Merge Replication

Post by UmF5bW9uZC » Thu, 01 Sep 2005 02:05:01

i 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

"msmith" wrote: