次の方法で共有


サブスクリプションの更新

Notification Services アプリケーションに対する既存のサブスクリプションを変更するには、Subscription クラスの Update メソッドを使用します。個々のサブスクリプション オブジェクトにアクセスするには、サブスクリプションの作成時に Notification Services によって決定されるサブスクリプション ID を使用するか、より一般的な方法として、SubscriptionEnumeration オブジェクトを使用してサブスクライバのサブスクリプションを反復処理します。

以下の例は、マネージ コードを使用してサブスクリプションを更新する方法と、Microsoft Visual Basic Scripting Edition (VBScript) を使用してサブスクリプションを更新する方法 (COM 相互運用の一例) を示しています。

マネージ コードの例

次の例は、サブスクリプションの列挙から特定のサブスクリプションを取得して、そのサブスクリプションを更新する方法を示しています。

ユーザー インターフェイスを開発する場合は、次の例のようにハードコード文字列を使用する代わりに、テキスト ボックスやリスト ボックスから値を取得できます。サブスクライバがサブスクリプションを選択できるようにするには、サブスクリプションの列挙から返されるサブスクリプション ID をリスト ボックスに設定します。これにより、サブスクライバがサブスクリプションを選択し、フィールド値を変更して、サブスクリプションを更新できます。

// 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");


//Create a SubscriptionEnumeration object.
// that contains all of the subscriber's subscriptions
// in a specific subscription class
SubscriptionEnumeration testSubscriptionEnumeration = 
    new SubscriptionEnumeration(testApplication, 
        "WeatherCity", "TestUser1");

//Iterate through the subscriptions, finding the subscription
// to match. In a user interface, you would probably list the 
// subscriptions in a list box and then let the user
// alter the data for the selected subscription
foreach (Subscription subscription in testSubscriptionEnumeration)
{
    String city = subscription.GetFieldValue("City").ToString();
    Console.WriteLine(city);
    Console.WriteLine("Subscription ID: {0}", subscription.SubscriptionId);
        if (city.Equals("Shoreline"))
            testSubscription.SubscriptionId = subscription.SubscriptionId;
}

// Set all of the subscription data fields 
testSubscription["DeviceName"] = "Work e-mail";
testSubscription["SubscriberLocale"] = "en-US";
testSubscription["City"] = "Edmonds";

testSubscription.Update();

COM 相互運用の例

次の VBScript の例は、Subscription クラスの SetFieldValue メソッドを使用して、アプリケーション固有のサブスクリプション フィールドの値を設定する方法を示しています。

Dim testInstance, testApplication, testSubscription

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

' Set the subscription ID so that 
'the correct record is updated.
testSubscription.SubscriptionId = "2"

' Update the subscription record.
testSubscription.SetFieldValue "DeviceName", "Work e-mail"
testSubscription.SetFieldValue "SubscriberLocale", "en-US"
testSubscription.SetFieldValue "City", "Orlando"
testSubscription.Update

wscript.echo "Subscription updated."

参照

概念

Subscription オブジェクトの作成
サブスクリプションの追加
サブスクリプションの削除
サブスクリプション フィールド情報の取得
サブスクライバ ロケール一覧の作成
タイム ゾーン一覧の作成

その他の技術情報

NS<SubscriptionClassName>View

ヘルプおよび情報

SQL Server 2005 の参考資料の入手