방법: 게시 삭제(RMO 프로그래밍)
RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 게시를 삭제할 수 있습니다. 게시를 제거하는 데 사용하는 RMO 클래스는 제거하는 게시 유형에 따라 달라집니다.
스냅숏 또는 트랜잭션 게시를 제거하려면
ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.
TransPublication 클래스의 인스턴스를 만듭니다.
게시에 대해 Name 및 DatabaseName 속성을 설정하고 ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.
IsExistingObject 속성을 통해 게시가 존재하는지 확인합니다. 이 속성의 값이 false이면 3단계의 게시 속성이 올바르게 정의되지 않았거나 게시가 없는 것입니다.
Remove 메서드를 호출합니다.
(옵션) 이 데이터베이스에 대한 다른 트랜잭션 게시가 없는 경우 다음과 같이 트랜잭션 게시에 대해 데이터베이스를 비활성화할 수 있습니다.
ReplicationDatabase 클래스의 인스턴스를 만듭니다. ConnectionContext 속성을 1단계에서 만든 ServerConnection 인스턴스로 설정합니다.
LoadProperties 메서드를 호출합니다. 이 메서드가 false를 반환할 경우 데이터베이스가 있는지 확인합니다.
EnabledTransPublishing 속성을 false로 설정합니다.
CommitPropertyChanges 메서드를 호출합니다.
연결을 닫습니다.
병합 게시를 제거하려면
ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.
MergePublication 클래스의 인스턴스를 만듭니다.
게시에 대해 Name 및 DatabaseName 속성을 설정하고 ConnectionContext 속성을 1단계에서 만든 연결로 설정합니다.
IsExistingObject 속성을 통해 게시가 존재하는지 확인합니다. 이 속성의 값이 false이면 3단계의 게시 속성이 올바르게 정의되지 않았거나 게시가 없는 것입니다.
Remove 메서드를 호출합니다.
(옵션) 이 데이터베이스에 대한 다른 병합 게시가 없는 경우 다음과 같이 병합 게시에 대해 데이터베이스를 비활성화할 수 있습니다.
ReplicationDatabase 클래스의 인스턴스를 만듭니다. ConnectionContext 속성을 1단계에서 만든 ServerConnection 인스턴스로 설정합니다.
LoadProperties 메서드를 호출합니다. 이 메서드가 false를 반환하면 데이터베이스가 있는지 확인합니다.
EnabledMergePublishing 속성을 false로 설정합니다.
CommitPropertyChanges 메서드를 호출합니다.
연결을 닫습니다.
예
다음 예에서는 트랜잭션 게시를 삭제합니다. 이 데이터베이스에 대한 다른 트랜잭션 게시가 없으면 트랜잭션 게시도 비활성화됩니다.
// Define the Publisher, publication database,
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks";
TransPublication publication;
ReplicationDatabase publicationDb;
// Create a connection to the Publisher
// using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);
try
{
conn.Connect();
// Set the required properties for the transactional publication.
publication = new TransPublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Delete the publication, if it exists and has no subscriptions.
if (publication.LoadProperties() && !publication.HasSubscription)
{
publication.Remove();
}
else
{
// Do something here if the publication does not exist
// or has subscriptions.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted. " +
"Ensure that the publication exists and that all " +
"subscriptions have been deleted.",
publicationName, publisherName));
}
// If no other transactional publications exists,
// disable publishing on the database.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (publicationDb.TransPublications.Count == 0)
{
publicationDb.EnabledTransPublishing = false;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The database {0} does not exist on {1}.",
publicationDbName, publisherName));
}
}
catch (Exception ex)
{
// Implement application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted.",
publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication database,
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks"
Dim publication As TransPublication
Dim publicationDb As ReplicationDatabase
' Create a connection to the Publisher
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
conn.Connect()
' Set the required properties for the transactional publication.
publication = New TransPublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Delete the publication, if it exists and has no subscriptions.
If publication.LoadProperties() And Not publication.HasSubscription Then
publication.Remove()
Else
' Do something here if the publication does not exist
' or has subscriptions.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted. " + _
"Ensure that the publication exists and that all " + _
"subscriptions have been deleted.", _
publicationName, publisherName))
End If
' If no other transactional publications exists,
' disable publishing on the database.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If publicationDb.TransPublications.Count = 0 Then
publicationDb.EnabledTransPublishing = False
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The database {0} does not exist on {1}.", _
publicationDbName, publisherName))
End If
Catch ex As Exception
' Implement application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted.", _
publicationName), ex)
Finally
conn.Disconnect()
End Try
다음 예에서는 병합 게시를 삭제합니다. 이 데이터베이스에 대한 다른 병합 게시가 없으면 병합 게시도 비활성화됩니다.
// Define the Publisher, publication database,
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks";
MergePublication publication;
ReplicationDatabase publicationDb;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the merge publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Delete the publication, if it exists and has no subscriptions.
if (publication.LoadProperties() && !publication.HasSubscription)
{
publication.Remove();
}
else
{
// Do something here if the publication does not exist
// or has subscriptions.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted. " +
"Ensure that the publication exists and that all " +
"subscriptions have been deleted.",
publicationName, publisherName));
}
// If no other merge publications exists,
// disable publishing on the database.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (publicationDb.MergePublications.Count == 0 && publicationDb.EnabledMergePublishing)
{
publicationDb.EnabledMergePublishing = false;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The database {0} does not exist on {1}.",
publicationDbName, publisherName));
}
}
catch (Exception ex)
{
// Implement application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted.",
publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication database,
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks"
Dim publication As MergePublication
Dim publicationDb As ReplicationDatabase
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Set the required properties for the merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Delete the publication, if it exists and has no subscriptions.
If (publication.LoadProperties() And Not publication.HasSubscription) Then
publication.Remove()
Else
' Do something here if the publication does not exist
' or has subscriptions.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted. " + _
"Ensure that the publication exists and that all " + _
"subscriptions have been deleted.", _
publicationName, publisherName))
End If
' If no other merge publications exists,
' disable publishing on the database.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If publicationDb.MergePublications.Count = 0 _
And publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = False
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The database {0} does not exist on {1}.", _
publicationDbName, publisherName))
End If
Catch ex As Exception
' Implement application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted.", _
publicationName), ex)
Finally
conn.Disconnect()
End Try