TransSynchronizationAgent Class
Provides the functionality of the Replication Distribution Agent.
네임스페이스: Microsoft.SqlServer.Replication
어셈블리: Microsoft.SqlServer.Replication (in microsoft.sqlserver.replication.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
<ComSourceInterfacesAttribute(GetType(IComStatusEvent))> _
<GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395")> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Class TransSynchronizationAgent
Inherits MarshalByRefObject
Implements IDisposable, ITransSynchronizationAgent
[ComVisibleAttribute(true)]
[ComSourceInterfacesAttribute(typeof(IComStatusEvent))]
[GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395")]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
public class TransSynchronizationAgent : MarshalByRefObject, IDisposable, ITransSynchronizationAgent
[ComVisibleAttribute(true)]
[ComSourceInterfacesAttribute(typeof(IComStatusEvent))]
[GuidAttribute(L"adeda98a-bdfc-4029-b6fb-991d6b468395")]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[PermissionSetAttribute(SecurityAction::Demand, Name=L"FullTrust")]
public ref class TransSynchronizationAgent : public MarshalByRefObject, IDisposable, ITransSynchronizationAgent
/** @attribute ComVisibleAttribute(true) */
/** @attribute ComSourceInterfacesAttribute(Microsoft.SqlServer.Replication.IComStatusEvent) */
/** @attribute GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395") */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust") */
public class TransSynchronizationAgent extends MarshalByRefObject implements IDisposable, ITransSynchronizationAgent
ComVisibleAttribute(true)
ComSourceInterfacesAttribute(Microsoft.SqlServer.Replication.IComStatusEvent)
GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395")
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class TransSynchronizationAgent extends MarshalByRefObject implements IDisposable, ITransSynchronizationAgent
주의
The TransSynchronizationAgent class supports the ability to programmatically synchronize subscriptions to transactional or snapshot publications.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
Microsoft.SqlServer.Replication.TransSynchronizationAgent
예
In the following example, the Synchronize method is called on the instance of the TransSynchronizationAgent class that is accessed from the SynchronizationAgent property to synchronize the push subscription.
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
TransSubscription subscription;
try
{
// Connect to the Publisher.
conn.Connect();
// Define the push subscription.
subscription = new TransSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = publicationDbName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.SubscriberName = subscriberName;
// If the push subscription exists, start the synchronization.
if (subscription.LoadProperties())
{
// Check that we have enough metadata to start the agent.
if (subscription.SubscriberSecurity != null)
{
// Synchronously start the Distribution Agent for the subscription.
subscription.SynchronizationAgent.Synchronize();
}
else
{
throw new ApplicationException("There is insufficent metadata to " +
"synchronize the subscription. Recreate the subscription with " +
"the agent job or supply the required agent properties at run time.");
}
}
else
{
// Do something here if the push subscription does not exist.
throw new ApplicationException(String.Format(
"The subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim subscriptionDbName As String = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Dim subscription As TransSubscription
Try
' Connect to the Publisher.
conn.Connect()
' Define the push subscription.
subscription = New TransSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = publicationDbName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.SubscriberName = subscriberName
' If the push subscription exists, start the synchronization.
If subscription.LoadProperties() Then
' Check that we have enough metadata to start the agent.
If Not subscription.SubscriberSecurity Is Nothing Then
' Synchronously start the Distribution Agent for the subscription.
subscription.SynchronizationAgent.Synchronize()
Else
Throw New ApplicationException("There is insufficent metadata to " + _
"synchronize the subscription. Recreate the subscription with " + _
"the agent job or supply the required agent properties at run time.")
End If
Else
' Do something here if the push subscription does not exist.
Throw New ApplicationException(String.Format( _
"The subscription to '{0}' does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
conn.Disconnect()
End Try
스레드 보안
The TransSynchronizationAgent class does not support multithreaded apartments. You can specify a single-threaded apartment by declaring the [STAThread]
attribute on the method that is the main entry point for the application. This is the default for Microsoft Windows-based applications that are created by using Microsoft Visual Studio.
플랫폼
개발 플랫폼
지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.
대상 플랫폼
지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.
참고 항목
참조
TransSynchronizationAgent Members
Microsoft.SqlServer.Replication Namespace
관련 자료
방법: 끌어오기 구독 동기화(RMO Programming)
방법: 밀어넣기 구독 동기화(Replication Programming)
Replication Distribution Agent