Jaa


Adding a Subscriber Device

The SubscriberDevice object exposes properties that allow you to set information about what type of device this is, what subscriber it belongs to, and how to deliver notifications to it. The Add method of this object writes that data to the Notification Services database. The examples below show how to add a subscriber device using managed code and using Microsoft Visual Basic Scripting Edition (VBScript) to illustrate COM interop.

Managed Code Example

The following code example shows how to use a SubscriberDevice object in managed code to add a subscriber device.

string instanceName = "Tutorial";

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

// Create the SubscriberDevice object.
SubscriberDevice testSubscriberDevice = 
    new SubscriberDevice(testInstance);

// Set the properties that describe the subscriber device record.
testSubscriberDevice.SubscriberId = "TestUser1";
testSubscriberDevice.DeviceAddress = "stephanie@adventure-works.com";
testSubscriberDevice.DeviceName = "Work e-mail";
testSubscriberDevice.DeviceTypeName = "e-mail";
testSubscriberDevice.DeliveryChannelName = "FileChannel";

// Add the subscriber device record to the database.
testSubscriberDevice.Add();

COM Interop Example

The following Microsoft Visual Basic Scripting Edition (VBScript) code example shows how to use a SubscriberDevice object in unmanaged code to add a subscriber device:

Dim testInstance, testSubscriberDevice
const instanceName = "Tutorial"

' Create the NSInstance object.
set testInstance = _
    WScript.CreateObject( _
    "Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName

' Create the SubscriberDevice object.
set testSubscriberDevice = _
    WScript.CreateObject( _
    "Microsoft.SqlServer.NotificationServices.SubscriberDevice")
testSubscriberDevice.Initialize (testInstance)

' Define device properties
testSubscriberDevice.SubscriberId = "TestUser2"
testSubscriberDevice.DeviceAddress = "david@adventure-works.com"
testSubscriberDevice.DeviceName = "Work e-mail"
testSubscriberDevice.DeviceTypeName = "e-mail"
testSubscriberDevice.DeliveryChannelName = "FileChannel"

' Add the subscriber device record to the database.
testSubscriberDevice.Add

wscript.echo "Subscriber device added."

See Also

Concepts

Creating a SubscriberDevice Object
Updating a Subscriber Device
Deleting a Subscriber Device
Populating a Delivery Channel List

Other Resources

NSSubscriberDeviceView

Help and Information

Getting SQL Server 2005 Assistance