更新訂閱者記錄
使用 Update 方法 (屬於 Subscriber 類別) 來修改 Notification Services 資料庫中的現有訂閱者資料。您存取訂閱者記錄的方式是建立訂閱者物件,然後設定 SubscriberId 屬性,或使用 SubscriberEnumeration 物件來取得 Notification Services 執行個體的訂閱者集合。
Managed 程式碼範例
下列程式碼範例顯示如何使用 Managed 程式碼中的 Subscriber 物件來更新訂閱者。
這個範例使用 Microsoft.SqlServer.NotificationServices 命名空間。
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.Enabled = false;
testSubscriber.Update();
COM Interop 範例
下列 Microsoft Visual Basic Scripting Edition (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"
' Set properties and update the subscriber record
testSubscriber.Enabled = false
testSubscriber.Update
wscript.echo "Subscriber updated."
請參閱
概念
建立訂閱者物件
新增訂閱者記錄
刪除訂閱者記錄
刪除相關的訂閱資訊
取得訂閱者的裝置及訂閱