共用方式為


新增訂閱者記錄

Subscriber 物件會公開可讓您設定 SubscriberId 值及指出訂閱者是否能夠接收通知的屬性。這個物件的 Add 方法會將這項資料寫入執行個體資料庫中。

ms171321.note(zh-tw,SQL.90).gif附註:
SubscriberId 的唯一性評估可能包括大小寫及開頭空白或結尾空白,這會隨著您選給 Notification Services 執行個體資料庫的定序而不同。

Managed 程式碼範例

下列程式碼範例顯示如何在 Managed 程式碼中,利用 Subscriber 物件來加入訂閱者。這個範例使用 EnabledSubscriberId 屬性的常值,但您可能會從您的訂閱管理介面中取得屬性值。

// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);

// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
        

// Set the properties that describe the subscriber record.
testSubscriber.Enabled = true;
testSubscriber.SubscriberId = "TestUser1";

// Add the subscriber record to the database.
testSubscriber.Add();

COM Interop 範例

下列 Microsoft Visual Basic Scripting Edition (VBScript) 程式碼範例顯示如何在 Managed 程式碼中,利用 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)
wscript.echo "Subscriber object created."


' Set the properties that describe the subscriber record.
testSubscriber.SubscriberId = "TestUser2"
testSubscriber.Enabled = true

' Add the subscriber record to the database.
testSubscriber.Add

wscript.echo "Subscriber added."

請參閱

概念

建立訂閱者物件
更新訂閱者記錄
刪除訂閱者記錄
刪除相關的訂閱資訊
取得訂閱者的裝置及訂閱

其他資源

NSSubscriberView

說明及資訊

取得 SQL Server 2005 協助