all groups > sql server replication > august 2006 >
You're in the

sql server replication

group:

GenerateSnapshot Progress Bar or any Status


GenerateSnapshot Progress Bar or any Status Rhett
8/16/2006 3:11:02 PM
sql server replication:
Hi All,

I'm using RMO to generate the initial snapshot and all works well unless I
try to present the user with some status in a winform application. The
GenerateSnapshot method will proceed up until the point where it starts bulk
copying data at which point I get the following error:

"The replication agent is being shut down because execution time for
status callback handlers has exceeded the system limit of 30 seconds, one
of the callback handlers may be accessing functionalities in the
replication
agent that are locked out while the agent is running."

Below is the code I use.

Thank you,
Rhett

public void GenerateSnapshot()
{
SnapshotGenerationAgent agent;

try
{
// Set the required properties for Snapshot Agent.
agent = new SnapshotGenerationAgent();
agent.Distributor = "DistributerName";
agent.DistributorSecurityMode = SecurityMode.Standard;
agent.DistributorLogin = "UserName";
agent.DistributorPassword = "Password";

agent.Publisher = "PublisherName";
agent.PublisherSecurityMode = SecurityMode.Standard;
agent.PublisherLogin = "UserName";
agent.PublisherPassword = "Password";

agent.Publication = "pubName";
agent.PublisherDatabase = "pubDbName";

agent.ReplicationType = ReplicationType.Merge;

agent.Status += new AgentCore.StatusEventHandler(agent_Status);

// Start the agent synchronously.
agent.GenerateSnapshot();
}
catch (Exception ex)
{
// Implement custom application error handling here.
throw new ApplicationException(String.Format(
"A snapshot could not be generated for the {0} publication."
, publicationName), ex);
}
}

void agent_Status(object sender, StatusEventArgs e)
{
safeStatus.Text = e.Message;
progressBar1.Value = Int32.Parse(e.PercentCompleted.ToString());
Application.DoEvents();
}
Re: GenerateSnapshot Progress Bar or any Status Raymond Mak [MSFT]
8/16/2006 5:06:17 PM
The regular Status event of the snaphot agent can be raised by different
threads which will most likely cause havoc in a WinForms environment (my
guess is that it is stuck in Application.DoEvents() when it is raised by an
auxiliary bcp thread). You can try hooking up your event handler to the
ComStatus event instead which is guaranteed to be raised by the thread
starting the snapshot agent although there may be significant latency for
receiving events from threads other than the main thread. (We basically
queue events from non-main threads up until the main thread gets around to
raise them.)

Hope that helps,

-Raymond
[quoted text, click to view]

AddThis Social Bookmark Button