Deleting Related Subscription Information
The DeleteSubscriptions method of the Subscriber class deletes existing subscription records for a given subscriber. You can delete all related subscriptions, just the subscriptions for one application, or just the subscriptions for one subscription class in one application. The examples below show how to delete a subscriber's subscriptions using managed code and using Microsoft Visual Basic Scripting Edition (VBScript) to illustrate COM interop.
Managed Code Example: Delete All Subscriptions
The following code example shows how to use a Subscriber object in managed code to delete all subscriptions belonging to the subscriber.
string instanceName = "Tutorial";
// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);
// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
// Set the subscriber ID so that the correct
// subscriber record is updated.
testSubscriber.SubscriberId = "TestUser1";
// Change subscriber data, then update the database.
testSubscriber.DeleteSubscriptions();
Using overloads of the DeleteSubscriptions method, you can also delete subscriptions for a single application or a single subscription class.
COM Interop Example: Delete All Subscriptions
The following VBScript code example shows how to use a Subscriber object in unmanaged code to delete all subscriptions belonging to a subscriber:
Dim testInstance, testSubscriber
const instanceName = "Tutorial"
' Create and initialize the NSInstance object.
set testInstance = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName
' Create and initialize the Subscriber object.
set testSubscriber = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.Subscriber")
testSubscriber.Initialize (testInstance)
' Set the subscriber ID.
testSubscriber.SubscriberId = "TestUser2"
' Delete the subscriber record
testSubscriber.DeleteSubscriptions Nothing, ""
wscript.echo "All TestUser2 subscriptions deleted."
See Also
Concepts
Deleting a Subscriber Record
Deleting a Subscription
Creating a Subscriber Object
Adding a Subscriber Record
Updating a Subscriber Record
Getting a Subscriber's Devices and Subscriptions