添加订阅方设备

SubscriberDevice 对象显示的属性允许您设置有关设备类型、设备所属订阅方以及如何将通知传递给设备的信息。该对象的 Add 方法将此数据写入 Notification Services 数据库中。下面的示例显示如何使用托管代码和 Microsoft Visual Basic 脚本版本 (VBScript) 添加订阅方设备以阐释 COM interop。

托管代码示例

以下代码示例显示如何在托管代码中使用 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 脚本版本 (VBScript) 代码示例显示如何在非托管代码中使用 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 帮助