Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
In diesem Thema wird beschrieben, wie Sie die Veröffentlichung und Verteilung in SQL Server 2014 mithilfe von SQL Server Management Studio, Transact-SQL oder Replikationsverwaltungsobjekten (Replication Management Objects, RMO) deaktivieren.
Sie können folgendermaßen vorgehen:
Löschen Sie alle Verteilungsdatenbanken für den Distributor.
Deaktivieren Sie alle Herausgeber, die den Distributor verwenden, und löschen Sie alle Publikationen auf diesen Herausgebern.
Löschen Sie alle Abonnements für die Publikationen. Daten in den Publikations- und Abonnementdatenbanken werden nicht gelöscht; Sie verliert jedoch die Synchronisierungsbeziehung zu allen Publikationsdatenbanken. Wenn die Daten beim Abonnenten gelöscht werden sollen, müssen Sie sie manuell löschen.
In diesem Themenbereich
Bevor Sie beginnen:
So deaktivieren Sie die Veröffentlichung und Verteilung, indem Sie Folgendes verwenden:
Bevor Sie beginnen
Voraussetzungen
- Um die Veröffentlichung und Verteilung zu deaktivieren, müssen alle Verteilungs- und Publikationsdatenbanken online sein. Gibt es Datenbankmomentaufnahmen für Verteilungs- oder Publikationsdatenbanken, müssen diese gelöscht werden, bevor Sie die Veröffentlichung und Verteilung deaktivieren. Eine Datenbankmomentaufnahme ist eine schreibgeschützte Offlinekopie einer Datenbank und ist nicht mit einer Replikationsmomentaufnahme verknüpft. Weitere Informationen finden Sie unter Datenbankmomentaufnahmen (SQL Server).
Verwendung von SQL Server Management Studio
Deaktivieren Sie die Veröffentlichung und Verteilung mithilfe des Assistenten zum Deaktivieren der Veröffentlichung und Verteilung.
So deaktivieren Sie die Veröffentlichung und Verteilung
Stellen Sie eine Verbindung mit dem Publisher oder Distributor her, den Sie in Microsoft SQL Server Management Studio deaktivieren möchten, und erweitern Sie dann den Serverknoten.
Klicken Sie mit der rechten Maustaste auf den Replikationsordner , und klicken Sie dann auf "Veröffentlichung und Verteilung deaktivieren".
Führen Sie die Schritte im Assistenten zur Deaktivierung von Veröffentlichungen und Verteilungen aus.
Verwenden von Transact-SQL
Die Veröffentlichung und Verteilung kann programmgesteuert mit gespeicherten Replikationsprozeduren deaktiviert werden.
So deaktivieren Sie die Veröffentlichung und Verteilung
Beenden Sie alle replikationsbezogenen Aufträge. Eine Liste der Auftragsnamen finden Sie im Abschnitt "Sicherheit des Agenten unter SQL Server-Agent" des Sicherheitsmodells des Replikations-Agenten.
Führen Sie bei jedem Abonnenten in der Abonnementdatenbank sp_removedbreplication aus, um Replikationsobjekte aus der Datenbank zu entfernen. Diese gespeicherte Prozedur entfernt keine Replikationsaufträge im Distributor.
Führen Sie in Publisher in der Publikationsdatenbank sp_removedbreplication aus, um Replikationsobjekte aus der Datenbank zu entfernen.
Wenn der Publisher einen Remoteverteiler verwendet, führen Sie sp_dropdistributor aus.
Führen Sie im Distributor sp_dropdistpublisher aus. Diese gespeicherte Prozedur sollte einmal für jeden Publisher ausgeführt werden, der beim Distributor registriert ist.
Führen Sie im Distributor sp_dropdistributiondb aus, um die Verteilungsdatenbank zu löschen. Diese gespeicherte Prozedur sollte einmal für jede Verteilungsdatenbank am Distributor ausgeführt werden. Dadurch werden auch alle Warteschlangenleser-Agent-Aufträge entfernt, die der Verteilungsdatenbank zugeordnet sind.
Führen Sie beim Distributor sp_dropdistributor aus, um die Verteilerbezeichnung vom Server zu entfernen.
Hinweis
Wenn alle Replikationsveröffentlichungs- und Verteilungsobjekte nicht verworfen werden, bevor Sie sp_dropdistpublisher und sp_dropdistributor ausführen, gibt diese Prozeduren einen Fehler zurück. Um alle replikationsbezogenen Objekte abzulegen, wenn ein Publisher oder Distributor abgelegt wird, muss der @no_checks Parameter auf 1 festgelegt werden. Wenn ein Herausgeber oder Verteiler offline oder nicht erreichbar ist, kann der parameter @ignore_distributor auf 1 festgelegt werden, sodass er gelöscht werden kann; Allerdings müssen alle Veröffentlichungs- und Verteilungsobjekte, die zurückbleiben, manuell entfernt werden.
Beispiele (Transact-SQL)
In diesem Beispielskript werden Replikationsobjekte aus der Abonnementdatenbank entfernt.
-- Remove replication objects from the subscription database on MYSUB.
DECLARE @subscriptionDB AS sysname
SET @subscriptionDB = N'AdventureWorks2012Replica'
-- Remove replication objects from a subscription database (if necessary).
USE master
EXEC sp_removedbreplication @subscriptionDB
GO
In diesem Beispielskript werden die Veröffentlichung und die Verteilung auf einem Server deaktiviert, der sowohl als Publisher als auch als Distributor fungiert, und die Verteilungsdatenbank wird gelöscht.
-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables
-- on the command line and in SQL Server Management Studio, see the
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".
-- Disable publishing and distribution.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB as sysname;
SET @distributionDB = N'distribution';
SET @publisher = $(DistPubServer);
SET @publicationDB = N'AdventureWorks2012';
-- Disable the publication database.
USE [AdventureWorks2012]
EXEC sp_removedbreplication @publicationDB;
-- Remove the registration of the local Publisher at the Distributor.
USE master
EXEC sp_dropdistpublisher @publisher;
-- Delete the distribution database.
EXEC sp_dropdistributiondb @distributionDB;
-- Remove the local server as a Distributor.
EXEC sp_dropdistributor;
GO
Verwenden von Replikationsverwaltungsobjekten (RMO)
So deaktivieren Sie die Veröffentlichung und Verteilung
Entfernen Sie alle Abonnements für Publikationen, die den Distributor verwenden. Weitere Informationen finden Sie unter "Löschen eines Pullabonnements " und "Löschen eines Pushabonnements".
Entfernen Sie alle Publikationen, die den Distributor verwenden, und deaktivieren Sie die Veröffentlichung für alle Datenbanken, wenn sich Publisher und Distributor auf demselben Server befinden. Weitere Informationen finden Sie unter Löschen einer Veröffentlichung.
Erstellen Sie mithilfe der ServerConnection Klasse eine Verbindung mit dem Distributor.
Erstellen Sie eine Instanz der DistributionPublisher Klasse. Geben Sie die Name Eigenschaft an, und übergeben Sie das ServerConnection Objekt aus Schritt 3.
(Optional) Rufen Sie die LoadProperties Methode auf, um die Eigenschaften des Objekts abzurufen und zu überprüfen, ob der Publisher vorhanden ist. Wenn diese Methode zurückgegeben wird
false, war der in Schritt 4 festgelegte Publisher-Name falsch, oder der Publisher wird von diesem Distributor nicht verwendet.Rufen Sie die Remove-Methode auf. Übergeben Sie den Wert
truefür force, wenn sich der Publisher und der Distributor auf verschiedenen Servern befinden und wenn der Publisher beim Distributor deinstalliert werden soll, ohne zuvor zu überprüfen, ob Publikationen noch beim Publisher vorhanden sind.Erstellen Sie eine Instanz der ReplicationServer Klasse. Übergeben Sie das ServerConnection Objekt aus Schritt 3.
Rufen Sie die UninstallDistributor-Methode auf. Um einen Wert von
truefür force zu übergeben, damit alle Replikationsobjekte beim Distributor entfernt werden, ohne zuerst zu überprüfen, ob alle lokalen Publikationsdatenbanken deaktiviert und die Verteilungsdatenbanken deinstalliert wurden.
Beispiele (RMO)
In diesem Beispiel wird die Publisher-Registrierung beim Distributor entfernt, die Verteilungsdatenbank gelöscht und der Distributor deinstalliert.
// 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 = "AdventureWorks2012";
// 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 AdventureWorks2012 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();
}
' Set the Distributor and publication database names.
' Publisher and Distributor are on the same server instance.
Dim publisherName As String = publisherInstance
Dim distributorName As String = subscriberInstance
Dim distributionDbName As String = "distribution"
Dim publicationDbName As String = "AdventureWorks2012"
' Create connections to the Publisher and Distributor
' using Windows Authentication.
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
Dim distributorConn As ServerConnection = New ServerConnection(distributorName)
' Create the objects we need.
Dim distributor As ReplicationServer
distributor = New ReplicationServer(distributorConn)
Dim publisher As DistributionPublisher
Dim distributionDb As DistributionDatabase
distributionDb = New DistributionDatabase(distributionDbName, distributorConn)
Dim publicationDb As ReplicationDatabase
publicationDb = New ReplicationDatabase(publicationDbName, publisherConn)
Try
' Connect to the Publisher and Distributor.
publisherConn.Connect()
distributorConn.Connect()
' Disable all publishing on the AdventureWorks2012 database.
If publicationDb.LoadProperties() Then
If publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = False
ElseIf publicationDb.EnabledTransPublishing Then
publicationDb.EnabledTransPublishing = False
End If
Else
Throw New ApplicationException( _
String.Format("The {0} database does not exist.", publicationDbName))
End If
' We cannot uninstall the Publisher if there are still Subscribers.
If distributor.RegisteredSubscribers.Count = 0 Then
' Uninstall the Publisher, if it exists.
publisher = New DistributionPublisher(publisherName, distributorConn)
If publisher.LoadProperties() Then
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))
End If
' Drop the distribution database.
If distributionDb.LoadProperties() Then
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))
End If
' Uninstall the Distributor, if it exists.
If distributor.LoadProperties() Then
' 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))
End If
Else
Throw New ApplicationException("You must first delete all subscriptions.")
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The Publisher and Distributor could not be uninstalled", ex)
Finally
publisherConn.Disconnect()
distributorConn.Disconnect()
End Try
In diesem Beispiel wird der Distributor deinstalliert, ohne zuerst lokale Publikationsdatenbanken zu deaktivieren oder die Verteilungsdatenbank zu löschen.
// Set the Distributor and publication database names.
// Publisher and Distributor are on the same server instance.
string distributorName = publisherInstance;
// Create connections to the Distributor
// using Windows Authentication.
ServerConnection conn = new ServerConnection(distributorName);
conn.DatabaseName = "master";
// Create the objects we need.
ReplicationServer distributor = new ReplicationServer(conn);
try
{
// Connect to the Publisher and Distributor.
conn.Connect();
// Uninstall the Distributor, if it exists.
// Use the force parameter to remove everthing.
if (distributor.IsDistributor && distributor.LoadProperties())
{
// Passing a value of true means that the Distributor
// is uninstalled even when publishing objects, subscriptions,
// and distribution databases exist on the server.
distributor.UninstallDistributor(true);
}
else
{
//Do something here if the distributor does not exist.
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The Publisher and Distributor could not be uninstalled", ex);
}
finally
{
conn.Disconnect();
}
' Set the Distributor and publication database names.
' Publisher and Distributor are on the same server instance.
Dim distributorName As String = publisherInstance
' Create connections to the Distributor
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(distributorName)
conn.DatabaseName = "master"
' Create the objects we need.
Dim distributor As ReplicationServer = New ReplicationServer(conn)
Try
' Connect to the Publisher and Distributor.
conn.Connect()
' Uninstall the Distributor, if it exists.
' Use the force parameter to remove everthing.
If distributor.IsDistributor And distributor.LoadProperties() Then
' Passing a value of true means that the Distributor
' is uninstalled even when publishing objects, subscriptions,
' and distribution databases exist on the server.
distributor.UninstallDistributor(True)
Else
'Do something here if the distributor does not exist.
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The Publisher and Distributor could not be uninstalled", ex)
Finally
conn.Disconnect()
End Try
Siehe auch
Konzepte für Replikationsverwaltungsobjekte
Konzepte für gespeicherte Replikationssystem-Prozeduren