刪除訂閱者裝置
SubscriberDevice 類別的 Delete 方法會刪除 Notification Services 資料庫中現有的訂閱者裝置記錄。下列範例顯示如何利用 Managed 程式碼來刪除訂閱者裝置,利用 Microsoft Visual Basic Scripting Edition (VBScript) 來說明 COM Interop。
如果您刪除最後一個訂閱者裝置,Notification Services 會在訂閱者裝置資料表中保留訂閱者的一個資料列,但會將它的所有屬性設為 NULL。
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 subscriber ID and device name
// so that the correct record is deleted.
testSubscriberDevice.SubscriberId = "TestUser1";
testSubscriberDevice.DeviceName = "Work E-mail";
// Delete the device
testSubscriberDevice.Delete();
COM Interop 範例
下列 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)
' Set the subscriber ID and device name
' so that the correct record is deleted.
testSubscriberDevice.SubscriberId = "TestUser2"
testSubscriberDevice.DeviceName = "Work e-mail"
' Delete the device
testSubscriberDevice.Delete()
wscript.echo "Subscriber device deleted."
請參閱
概念
建立 SubscriberDevice 物件
新增訂閱者裝置
更新訂閱者裝置
擴展傳遞通道清單