Sunday, February 19, 2012

Cannot set the ProfileName on a merge agent

Hi,

I am trying to create a new merge subscription using RMO on Sql 2005, but I want the new agent to use a non-default profile.

I can set the ProfileName on the agent but it seems to have no affect. I was wondering, do I have the wrong Profile name?

This is the code I'm using

subscription = new MergeSubscription();

subscription.ConnectionContext = conn;

subscription.SubscriberName = server;

subscription.SubscriberSecurity.SqlStandardLogin = sqlUserName;

subscription.SubscriberSecurity.SqlStandardPassword = sqlPassword;

subscription.SubscriberSecurity.WindowsAuthentication = useWindowsAuth;

subscription.PublicationName = publication.Name;

subscription.DatabaseName = publication.DatabaseName;

subscription.SubscriptionDBName = database;

subscription.SyncType = SubscriptionSyncType.Automatic;

subscription.SubscriberType = MergeSubscriberType.Global;

subscription.Priority = 75;

subscription.UseInteractiveResolver = false;

if(hostNameOverride != null && hostNameOverride.Length > 0)

subscription.HostName = hostNameOverride;

subscription.SynchronizationAgentProcessSecurity.Login = agentUserName;

subscription.SynchronizationAgentProcessSecurity.Password = agentPassword;

// Create the push subscription.

subscription.Create();

if (subscription.SynchronizationAgent != null)

subscription.SynchronizationAgent.ProfileName = "High Volume Server-to-Server Profile";

Can anyone tell me what I've done wrong?

Regards

Graham

Agent has a corresponding profile, which has existed and you can not change its name. As for your case, you may try to create a new non-default profile and give it with the name you set. Also set the new profile as your merge agent profile.

Hope it will help.

THanks

Yunjing

|||

Thanks Yungjing,

are you saying that is it not possible to create a subscription and the subscription use one of the pre-defined agent profiles?

I can change the profile of an existing agent using the UI of the replication monitor, so I would have thought it should be possible using RMO!!

Regards

Graham

|||

No, this is not what I mean.

But I understand your issue this time. Originally, I thought you tried to change profile name through calling subscription.SynchronizationAgent.ProfileName = "High Volume Server-to-Server Profile".

To change agent with another pre-defined agent profile, you should use

RMO class: AgentProfile

Method: public void AssignToAgent(string distributionDBName, int agentID)

It will call SP sp_update_agent_profile as UI does.

Hope it will help this time. :-)

-Yunjing

|||

Thats just the answer I was looking for, thanks Yunjing.

However, I have one small problem. Where do I find the agentID as an integer from?

My code has just created a new subscription. The only reference to an agent Job ID I can find is one the MergeSubscription class, but this is a string, and it won't convert to an integer.

Thank you once again.

Graham

|||

Here are some sample code, you may refer to get help for your conversion case.

............

DataTable dt = ds.Tables[0];
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
// Column 0 is always the Dist DB
string distDB = (string)dr[0];
int agentID = (int)dr[nColAgentID];
agentProfile.AssignToAgent(distDB, agentID);
}

............................

Thanks

Yunjing

No comments:

Post a Comment