Jaa


Adding a Subscriber Record

The Subscriber object exposes properties that allow you to set the SubscriberId value and indicate whether the subscriber is enabled to receive notifications. The Add method of this object writes that data to the instance database.

Note

Depending on the collation you have selected for your Notification Services instance database, evaluation of the uniqueness of the SubscriberId may include case and leading or trailing spaces.

Managed Code Example

The following code example shows how to use a Subscriber object in managed code to add a subscriber. The example uses literal values for the Enabled and SubscriberId properties, but you will likely get the property values from your subscription management interface.

// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);

// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
        

// Set the properties that describe the subscriber record.
testSubscriber.Enabled = true;
testSubscriber.SubscriberId = "TestUser1";

// Add the subscriber record to the database.
testSubscriber.Add();

COM Interop Example

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


' Set the properties that describe the subscriber record.
testSubscriber.SubscriberId = "TestUser2"
testSubscriber.Enabled = true

' Add the subscriber record to the database.
testSubscriber.Add

wscript.echo "Subscriber added."

See Also

Concepts

Creating a Subscriber Object
Updating a Subscriber Record
Deleting 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