共用方式為


新增訂閱者裝置

SubscriberDevice 物件會顯示屬性讓您設定裝置類型相關資訊 - 亦即,裝置屬於哪個訂閱者,以及如何將通知傳遞給它。這個物件的 Add 方法會將該資料寫入 Notification Services 資料庫。下列範例顯示如何利用 Managed 程式碼和 Microsoft Visual Basic Scripting Edition (VBScript) 加入訂閱者裝置來說明 COM interop。

Managed 程式碼範例

下列程式碼範例顯示如何利用 Managed 程式碼中的 SubscriberDevice 物件加入訂閱者裝置。

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

下列 Microsoft Visual Basic Scripting Edition (VBScript) 程式碼範例顯示如何利用 Unmanaged 程式碼中的 SubscriberDevice 物件加入訂閱者裝置:

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

請參閱

概念

建立 SubscriberDevice 物件
更新訂閱者裝置
刪除訂閱者裝置
擴展傳遞通道清單

其他資源

NSSubscriberDeviceView

說明及資訊

取得 SQL Server 2005 協助