Populating a Delivery Channel List

If your application supports multiple delivery channels, such as an e-mail based delivery channel and a Windows Messenger delivery channel, you can provide a list of delivery channels so that subscribers can create subscriber devices and then select those subscriber devices for individual subscriptions.

In SQL Server 2005, the Notification Services Object Model (NMO) provides classes for enumerating instance and application properties. To enumerate delivery channels, use the instance's DeliveryChannels property to get the collection of delivery channels defined for the Notification Services instance. The NMO classes are in the Microsoft.SqlServer.Management.Nmo namespace, which is in the Microsoft.SqlServer.Smo assembly.

It is possible that not all of the delivery channels offered in a Notification Services instance are appropriate for all of your applications. Make sure that your user interface offers only those delivery channels that are valid for the application.

Managed Code Example

The following code example shows how to use the instance's DeliveryChannels property to get the collection of delivery channels defined for the Notification Services instance:

Note

The following sample requires a reference to the Microsoft.SqlServer.Management.Smo assembly. Both the Microsoft.SqlServer.Management.Nmo and Microsoft.SqlServer.Management.Smo namespaces are in the SMO assembly. To designate the namespaces of the classes, this sample uses the nmo and smo namespace aliases.

Use the following using directives when running this example:

using System;
using Microsoft.SqlServer.NotificationServices;
using nmo = Microsoft.SqlServer.Management.Nmo;
using smo = Microsoft.SqlServer.Management.Smo;

Then use the following code to enumerate the delivery channels:

// Specify the Database Engine instance that hosts the 
// Notificaiton Services instance and get a reference to 
// the NotificationServices object.
smo.Server server = new smo.Server("MyServer");
nmo.NotificationServices notificationServices = server.NotificationServices;

// Get the Notification Services instance.
nmo.Instance nsinst = notificationServices.Instances ["Tutorial"];

// Get the instance's collection of delivery channels.
nmo.DeliveryChannelCollection dcCollection = nsinst.DeliveryChannels;

// Enumerate the delivery channels.
foreach (nmo.DeliveryChannel dc in dcCollection)
{
    Console.WriteLine(dc.Name);
}

COM Interop Example

NMO does not support COM interop. If you need to use COM interop to enumerate delivery channels, you must use the deprecated DeliveryChannel and DeliveryChannelEnumeration class from the Microsoft.SqlServer.NotificationServices namespace to get the collection of delivery channels defined for the Notification Services instance:

Dim testInstance, testDeliveryChannelEnumeration
const instanceName = "Tutorial"

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

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

' Step through the enumeration, printing the 
' delivery channel names.
for each channel in testDeliveryChannelEnumeration
    Wscript.Echo "Delivery Channel: ", _ 
        channel.DeliveryChannelName
next

wscript.echo "Done!"

See Also

Concepts

Creating a SubscriberDevice Object
Adding a Subscriber Device
Updating a Subscriber Device
Deleting a Subscriber Device

Other Resources

NSSubscriberDeviceView

Help and Information

Getting SQL Server 2005 Assistance