ReplicationDatabase.TransPublications 속성

Returns the transactional or snapshot publications defined on the replication database.

네임스페이스:  Microsoft.SqlServer.Replication
어셈블리:  Microsoft.SqlServer.Rmo(Microsoft.SqlServer.Rmo.dll)

구문

‘선언
Public ReadOnly Property TransPublications As TransPublicationCollection 
    Get
‘사용 방법
Dim instance As ReplicationDatabase 
Dim value As TransPublicationCollection 

value = instance.TransPublications
public TransPublicationCollection TransPublications { get; }
public:
property TransPublicationCollection^ TransPublications {
    TransPublicationCollection^ get ();
}
member TransPublications : TransPublicationCollection
function get TransPublications () : TransPublicationCollection

속성 값

유형: Microsoft.SqlServer.Replication.TransPublicationCollection
A TransPublicationCollection of TransPublication objects.

주의

TransPublication objects in a TransPublicationCollection can be accessed using a string indexer (name) or a numeric indexer (ordinal).

The TransPublications property can be retrieved by members of the sysadmin fixed server role or by members of the db_owner fixed database role on the publication database.

            // Define the Publisher, publication database, 
            // and publication names.
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksProductTran";
            string publicationDbName = "AdventureWorks2012";

            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 = "AdventureWorks2012"

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

참고 항목

참조

ReplicationDatabase 클래스

Microsoft.SqlServer.Replication 네임스페이스

관련 자료

방법: 게시 삭제(RMO 프로그래밍)