Subscription.Remove Method
Deletes the subscription registration at the Publisher and removes replication objects at the Subscriber for a push subscription.
Espacio de nombres: Microsoft.SqlServer.Replication
Ensamblado: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)
Sintaxis
'Declaración
Public Sub Remove
public void Remove ()
public:
void Remove ()
public void Remove ()
public function Remove ()
Notas
The Remove method can only be called by members of the sysadmin fixed server role at the Publisher or by members of the db_owner fixed database role on the publication database.
Calling Remove is equivalent to executing sp_dropsubscription or sp_dropmergesubscription.
This namespace, class, or member is supported only in version 2.0 of the Microsoft .NET Framework.
Ejemplo
This example deletes a push subscription to a transactional publication.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksProductTran";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
//Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
// Create the objects that we need.
TransSubscription subscription;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new TransSubscription();
subscription.ConnectionContext = conn;
subscription.SubscriberName = subscriberName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.DatabaseName = publicationDbName;
// Delete the pull subscription, if it exists.
if (subscription.IsExistingObject)
{
// Delete the pull subscription at the Subscriber.
subscription.Remove();
}
else
{
throw new ApplicationException(String.Format(
"The subscription to {0} does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be deleted.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksProductTran"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
'Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim subscription As TransSubscription
Try
' Connect to the Subscriber.
conn.Connect()
' Define the pull subscription.
subscription = New TransSubscription()
subscription.ConnectionContext = conn
subscription.SubscriberName = subscriberName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.DatabaseName = publicationDbName
' Delete the pull subscription, if it exists.
If subscription.IsExistingObject Then
' Delete the pull subscription at the Subscriber.
subscription.Remove()
Else
Throw New ApplicationException(String.Format( _
"The subscription to {0} does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be deleted.", publicationName), ex)
Finally
conn.Disconnect()
End Try
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
//Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
// Create the objects that we need.
MergeSubscription subscription;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new MergeSubscription();
subscription.ConnectionContext = conn;
subscription.SubscriberName = subscriberName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.DatabaseName = publicationDbName;
// Delete the pull subscription, if it exists.
if (subscription.IsExistingObject)
{
// Delete the pull subscription at the Subscriber.
subscription.Remove();
}
else
{
throw new ApplicationException(String.Format(
"The subscription to {0} does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be deleted.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
'Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim subscription As MergeSubscription
Try
' Connect to the Subscriber.
conn.Connect()
' Define the pull subscription.
subscription = New MergeSubscription()
subscription.ConnectionContext = conn
subscription.SubscriberName = subscriberName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.DatabaseName = publicationDbName
' Delete the pull subscription, if it exists.
If subscription.IsExistingObject Then
' Delete the pull subscription at the Subscriber.
subscription.Remove()
Else
Throw New ApplicationException(String.Format( _
"The subscription to {0} does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be deleted.", publicationName), ex)
Finally
conn.Disconnect()
End Try
This example deletes a push subscription to a merge publication.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";
//Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
// Create the objects that we need.
MergeSubscription subscription;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new MergeSubscription();
subscription.ConnectionContext = conn;
subscription.SubscriberName = subscriberName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.DatabaseName = publicationDbName;
// Delete the pull subscription, if it exists.
if (subscription.IsExistingObject)
{
// Delete the pull subscription at the Subscriber.
subscription.Remove();
}
else
{
throw new ApplicationException(String.Format(
"The subscription to {0} does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be deleted.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"
'Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim subscription As MergeSubscription
Try
' Connect to the Subscriber.
conn.Connect()
' Define the pull subscription.
subscription = New MergeSubscription()
subscription.ConnectionContext = conn
subscription.SubscriberName = subscriberName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.DatabaseName = publicationDbName
' Delete the pull subscription, if it exists.
If subscription.IsExistingObject Then
' Delete the pull subscription at the Subscriber.
subscription.Remove()
Else
Throw New ApplicationException(String.Format( _
"The subscription to {0} does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be deleted.", publicationName), ex)
Finally
conn.Disconnect()
End Try
Seguridad para subprocesos
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Plataformas
Plataformas de desarrollo
Para obtener una lista de las plataformas compatibles, vea Requisitos de hardware y software para instalar SQL Server 2005.
Plataformas de destino
Para obtener una lista de las plataformas compatibles, vea Requisitos de hardware y software para instalar SQL Server 2005.
Vea también
Referencia
Subscription Class
Subscription Members
Microsoft.SqlServer.Replication Namespace