Compartilhar via


Deleting a Subscriber Record

The Delete method of the Subscriber class deletes an existing subscriber record in the instance database.

Important

In enabled Notification Services applications, deleting a subscriber record automatically deletes all subscriber devices and subscriptions associated with that subscriber ID. In disabled Notification Services applications, deleting a subscriber record causes associated subscriptions to be orphaned. You should remove orphaned subscriptions from your applications.

Managed Code Example

The following code example shows how to use a Subscriber object in managed code to delete a 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.Delete();

COM Interop Example

The following Microsoft Visual Basic Scripting Edition (VBScript) code example shows how to use a Subscriber object in unmanaged code to delete 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.Delete

wscript.echo "Subscriber deleted."

See Also

Concepts

Creating a Subscriber Object
Adding a Subscriber Record
Updating a Subscriber Record
Deleting Related Subscription Information
Getting a Subscriber's Devices and Subscriptions

Other Resources

NSSubscriberView

Help and Information

Getting SQL Server 2005 Assistance