共用方式為


擴展傳遞通道清單

如果您的應用程式支援多重傳遞通道,如以電子郵件為基礎的傳遞通道和 Windows Messenger 傳遞通道,您可以提供一份傳遞通道清單,使訂閱者能夠建立訂閱者裝置,再針對個別訂閱來選取這些訂閱者裝置。

在 SQL Server 2005 中,Notification Services Object Model (NMO) 提供了用來列舉執行個體和應用程式屬性的類別。若要列舉傳遞通道,請利用執行個體的 DeliveryChannels 屬性來取得定義給 Notification Services 執行個體的傳遞通道集合。NMO 類別在 Microsoft.SqlServer.Management.Nmo 命名空間中,這個命名空間則在 Microsoft.SqlServer.Smo 組件中。

Notification Services 執行個體所提供的所有傳遞通道未必全部適用於您的所有應用程式。請確定您的使用者介面只提供對應用程式有效的傳遞通道。

Managed 程式碼範例

下列程式碼範例顯示如何利用執行個體的 DeliveryChannels 屬性來取得定義給 Notification Services 執行個體的傳遞通道集合:

ms166392.note(zh-tw,SQL.90).gif附註:
下列範例需要對於 Microsoft.SqlServer.Management.Smo 組件的參考。Microsoft.SqlServer.Management.NmoMicrosoft.SqlServer.Management.Smo 命名空間都在 SMO 組件中。為了指定類別的命名空間,這個範例使用 nmosmo 命名空間別名。

當執行這個範例時,請使用下列 using 指示詞:

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

之後,請利用下列程式碼來列舉傳遞通道:

// 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 範例

NMO 不支援 COM Interop。如果您必須利用 COM Interop 來列舉傳遞通道,您必須使用 Microsoft.SqlServer.NotificationServices 命名空間中已被取代的 DeliveryChannelDeliveryChannelEnumeration 類別,以取得定義給 Notification Services 執行個體的傳遞通道集合:

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!"

請參閱

概念

建立 SubscriberDevice 物件
新增訂閱者裝置
更新訂閱者裝置
刪除訂閱者裝置

其他資源

NSSubscriberDeviceView

說明及資訊

取得 SQL Server 2005 協助