刪除相關的訂閱資訊
Subscriber 類別的 DeleteSubscriptions 方法會刪除給定訂閱者現有的訂閱記錄。您可以刪除所有相關的訂閱、只刪除單一應用程式的訂閱,或只刪除單一應用程式中之單一訂閱類別的訂閱。下列範例顯示如何利用 Managed 程式碼來刪除訂閱者的訂閱,利用 Microsoft Visual Basic Scripting Edition (VBScript) 來說明 COM Interop。
Managed 程式碼範例:刪除所有訂閱
下列程式碼範例顯示如何在 Managed 程式碼中,利用 Subscriber 物件來刪除屬於訂閱者的所有訂閱。
string instanceName = "Tutorial";
// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);
// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
// Set the subscriber ID so that the correct
// subscriber record is updated.
testSubscriber.SubscriberId = "TestUser1";
// Change subscriber data, then update the database.
testSubscriber.DeleteSubscriptions();
您也可以利用 DeleteSubscriptions 方法的多載來刪除單一應用程式或單一訂閱類別的訂閱。
COM Interop 範例:刪除所有訂閱
下列 VBScript 程式碼範例顯示如何在 Unmanaged 程式碼中,利用 Subscriber 物件來刪除屬於訂閱者的所有訂閱:
Dim testInstance, testSubscriber
const instanceName = "Tutorial"
' Create and initialize the NSInstance object.
set testInstance = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName
' Create and initialize the Subscriber object.
set testSubscriber = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.Subscriber")
testSubscriber.Initialize (testInstance)
' Set the subscriber ID.
testSubscriber.SubscriberId = "TestUser2"
' Delete the subscriber record
testSubscriber.DeleteSubscriptions Nothing, ""
wscript.echo "All TestUser2 subscriptions deleted."
請參閱
概念
刪除訂閱者記錄
刪除訂閱
建立訂閱者物件
新增訂閱者記錄
更新訂閱者記錄
取得訂閱者的裝置及訂閱