共用方式為


建立訂閱物件

您必須建立 Subscription 類別的物件,來加入、刪除和更新 Notification Services 應用程式中的訂閱資訊。下列範例會顯示如何利用 Managed 程式碼來建立 Subscription 物件,利用 Microsoft Visual Basic Scripting Edition (VBScript) 來說明 COM Interop。

Managed 程式碼範例

下列程式碼範例會顯示如何利用參數化建構函式,來建立和初始化 Subscription 物件。Subscription 物件立即可用。

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

// Create the NSApplication object.
NSApplication testApplication =
    new NSApplication(testInstance, "Weather");

// Create the Subscription object.
Subscription testSubscription =
    new Subscription(testApplication, "WeatherCity");

COM Interop 範例

下列 VBScript 範例會顯示如何利用預設建構函式,來建立 Subscription 物件,再呼叫 Initialize 方法來將它初始化,以透過 COM Interop 來建立和初始化這個物件。

Dim testInstance, testApplication, testSubscription, subscriptionId

const instanceName = "Tutorial"
const applicationName = "Weather"
const subscriptionClassName = "WeatherCity"

' Create the NSInstance object.
set testInstance = WScript.CreateObject( _ 
    "Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName

' Create the NSApplication object.
set testApplication = WScript.CreateObject( _ 
    "Microsoft.SqlServer.NotificationServices.NSApplication")
testApplication.Initialize (testInstance), applicationName

' Create the Subscription object.
set testSubscription = WScript.CreateObject( _
    "Microsoft.SqlServer.NotificationServices.Subscription")
testSubscription.Initialize (testApplication), subscriptionClassName

請參閱

概念

新增訂閱
更新訂閱
刪除訂閱
取得訂閱欄位資訊
擴展訂閱者地區設定程式碼
擴展時區清單

說明及資訊

取得 SQL Server 2005 協助