Udostępnij za pośrednictwem


Właściwość ReplicationServer.RegisteredSubscribers

Pobiera subskrybentów zarejestrowany z Wydawca.

Przestrzeń nazw:  Microsoft.SqlServer.Replication
Zestaw:  Microsoft.SqlServer.Rmo (w Microsoft.SqlServer.Rmo.dll)

Składnia

'Deklaracja
Public ReadOnly Property RegisteredSubscribers As RegisteredSubscriberCollection
    Get
'Użycie
Dim instance As ReplicationServer
Dim value As RegisteredSubscriberCollection

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

Wartość właściwości

Typ: Microsoft.SqlServer.Replication.RegisteredSubscriberCollection
A RegisteredSubscriberCollection obiekt reprezentujący zarejestrowanych subskrybentów po aktualnie podłączonych wystąpienie z SQL Server jest Wydawca.

Uwagi

A RegisteredSubscriber obiektu zwróconego RegisteredSubscriberCollection można uzyskać dostęp za pomocą liczby całkowitej lub indeksatora ciąg.

RegisteredSubscribers właściwość mogą być pobierane przez społeczeństwo stała rola bazy danych.

Ten obszar nazw, klasy lub element członkowski jest obsługiwany tylko w wersja 2.0.NET Framework.

Przykłady

          // Set the Distributor and publication database names.
            // Publisher and Distributor are on the same server instance.
            string publisherName = publisherInstance;
            string distributorName = publisherInstance;
            string distributionDbName = "distribution";
            string publicationDbName = "AdventureWorks";

            // Create connections to the Publisher and Distributor
            // using Windows Authentication.
            ServerConnection publisherConn = new ServerConnection(publisherName);
            ServerConnection distributorConn = new ServerConnection(distributorName);

            // Create the objects we need.
            ReplicationServer distributor =
                new ReplicationServer(distributorConn);
            DistributionPublisher publisher;
            DistributionDatabase distributionDb =
                new DistributionDatabase(distributionDbName, distributorConn);
            ReplicationDatabase publicationDb;
            publicationDb = new ReplicationDatabase(publicationDbName, publisherConn);

            try
            {
                // Connect to the Publisher and Distributor.
                publisherConn.Connect();
                distributorConn.Connect();

                // Disable all publishing on the AdventureWorks2008R2 database.
                if (publicationDb.LoadProperties())
                {
                    if (publicationDb.EnabledMergePublishing)
                    {
                        publicationDb.EnabledMergePublishing = false;
                    }
                    else if (publicationDb.EnabledTransPublishing)
                    {
                        publicationDb.EnabledTransPublishing = false;
                    }
                }
                else
                {
                    throw new ApplicationException(
                        String.Format("The {0} database does not exist.", publicationDbName));
                }

                // We cannot uninstall the Publisher if there are still Subscribers.
                if (distributor.RegisteredSubscribers.Count == 0)
                {
                    // Uninstall the Publisher, if it exists.
                    publisher = new DistributionPublisher(publisherName, distributorConn);
                    if (publisher.LoadProperties())
                    {
                        publisher.Remove(false);
                    }
                    else
                    {
                        // Do something here if the Publisher does not exist.
                        throw new ApplicationException(String.Format(
                            "{0} is not a Publisher for {1}.", publisherName, distributorName));
                    }

                    // Drop the distribution database.
                    if (distributionDb.LoadProperties())
                    {
                        distributionDb.Remove();
                    }
                    else
                    {
                        // Do something here if the distribition DB does not exist.
                        throw new ApplicationException(String.Format(
                            "The distribution database '{0}' does not exist on {1}.",
                            distributionDbName, distributorName));
                    }

                    // Uninstall the Distributor, if it exists.
                    if (distributor.LoadProperties())
                    {
                        // Passing a value of false means that the Publisher 
                        // and distribution databases must already be uninstalled,
                        // and that no local databases be enabled for publishing.
                        distributor.UninstallDistributor(false);
                    }
                    else
                    {
                        //Do something here if the distributor does not exist.
                        throw new ApplicationException(String.Format(
                            "The Distributor '{0}' does not exist.", distributorName));
                    }
                }
                else
                {
                    throw new ApplicationException("You must first delete all subscriptions.");
                }
            }
            catch (Exception ex)
            {
                // Implement appropriate error handling here.
                throw new ApplicationException("The Publisher and Distributor could not be uninstalled", ex);
            }
            finally
            {
                publisherConn.Disconnect();
                distributorConn.Disconnect();
            }