SynchronizeWithJob 메서드
Starts the agent job to synchronize the subscription.
네임스페이스: Microsoft.SqlServer.Replication
어셈블리: Microsoft.SqlServer.Rmo.dll의 Microsoft.SqlServer.Rmo
구문
‘선언
Public Overrides Sub SynchronizeWithJob
‘사용 방법
Dim instance As TransPullSubscription
instance.SynchronizeWithJob()
public override void SynchronizeWithJob()
public:
virtual void SynchronizeWithJob() override
abstract SynchronizeWithJob : unit -> unit
override SynchronizeWithJob : unit -> unit
public override function SynchronizeWithJob()
주의
Use the TransSynchronizationAgent object returned by the SynchronizationAgent property to start the Distribution Agent synchronously.
If the pull subscription is created with a value of false for CreateSyncAgentByDefault, the default, a Distribution Agent job for the subscription is not created and calling SynchronizeWithJob causes an exception.
Call the StopSynchronizationJob method to stop the job if it is currently running.
The job is not able to start if the Microsoft SQL Server Agent Service is not running. Also if a snapshot is not generated, running the agent job may not synchronize the subscription.
If you have set additional properties on this instance of TransPullSubscription, call CommitPropertyChanges before calling SynchronizeWithJob.
The SynchronizeWithJob method can only be called by members of the sysadmin fixed server role at the Subscriber or by members of the db_owner fixed database role on the subscription database.
This namespace, class, or member is supported only in version 2.0 of the .NET Framework.
예제
// Define server, publication, and database names.
String subscriberName = subscriberInstance;
String publisherName = publisherInstance;
String publicationName = "AdvWorksProductTran";
String publicationDbName = "AdventureWorks";
String subscriptionDbName = "AdventureWorksReplica";
// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);
TransPullSubscription subscription;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define subscription properties.
subscription = new TransPullSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = subscriptionDbName;
subscription.PublisherName = publisherName;
subscription.PublicationDBName = publicationDbName;
subscription.PublicationName = publicationName;
// If the pull subscription and the job exists, start the agent job.
if (subscription.LoadProperties() && subscription.AgentJobId != null)
{
subscription.SynchronizeWithJob();
}
else
{
// Do something here if the subscription does not exist.
throw new ApplicationException(String.Format(
"A subscription to '{0}' does not exists on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Do appropriate error handling here.
throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
conn.Disconnect();
}
' Define server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks"
Dim subscriptionDbName As String = "AdventureWorksReplica"
' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)
Dim subscription As TransPullSubscription
Try
' Connect to the Subscriber.
conn.Connect()
' Define subscription properties.
subscription = New TransPullSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = subscriptionDbName
subscription.PublisherName = publisherName
subscription.PublicationDBName = publicationDbName
subscription.PublicationName = publicationName
' If the pull subscription and the job exists, start the agent job.
If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then
subscription.SynchronizeWithJob()
Else
' Do something here if the subscription does not exist.
Throw New ApplicationException(String.Format( _
"A subscription to '{0}' does not exists on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Do appropriate error handling here.
Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
conn.Disconnect()
End Try