次の方法で共有


EventClass Class

Notification Services Application で使用するイベント クラスを表します。

名前空間: Microsoft.SqlServer.Management.Nmo
アセンブリ: Microsoft.SqlServer.Smo (microsoft.sqlserver.smo.dll 内)

構文

'宣言
Public NotInheritable Class EventClass
    Inherits NamedSmoObject
public sealed class EventClass : NamedSmoObject
public ref class EventClass sealed : public NamedSmoObject
public final class EventClass extends NamedSmoObject
public final class EventClass extends NamedSmoObject

解説

イベント クラスとは、Notification Services アプリケーションが使用するイベントの型です。アプリケーションを定義するときには、アプリケーション データベースで保持するイベントのすべての種類に対してイベント クラスを定義します。

アプリケーションからイベント クラスを削除した後、アプリケーションを更新すると、アプリケーション データベース中の基になるテーブルとインデックスが削除されます。元のイベント クラスのテーブル内に存在するデータは、すべて完全に削除されます。

1 つの Notification Services アプリケーションには、0 ~ 64 個のイベント クラスを実装できます。イベントを外部のデータベースに保持し、サブスクリプション ルールでデータベースをクエリする場合には、これらのイベントに対するイベント クラスは定義しません。

継承階層

System.Object
   Microsoft.SqlServer.Management.Smo.SmoObjectBase
     Microsoft.SqlServer.Management.Smo.SqlSmoObject
       Microsoft.SqlServer.Management.Smo.NamedSmoObject
        Microsoft.SqlServer.Management.Nmo.EventClass

使用例

次の例は、すべてのイベント クラス プロパティと、イベント クラスにフィールドを追加するためのすべてのメソッドを使用して、イベント クラスを定義する方法を示しています。

EventClass flightEvents = 
    new EventClass(myApplication, "FlightEvents");

flightEvents.FileGroup = "PRIMARY";

// Add an orgin field to the end of the field collection
EventField eventOrgin = 
    new EventField(flightEvents, "LeavingFrom");
eventOrgin.Type = "nvarchar(6)";
eventOrgin.TypeModifier = "not null";
flightEvents.EventFields.Add(eventOrgin);

// Define a price field and add it at position 1
EventField eventPrice = new EventField(flightEvents, "Price");
eventPrice.Type = "float";
flightEvents.EventFields.Add(eventPrice, 1);

// Define a destination field and add it before the Price field
EventField eventDestination = 
    new EventField(flightEvents, "GoingTo");
eventDestination.Type = "nvarchar(6)";
flightEvents.EventFields.Add(eventDestination, "Price");

// Add the event class to the application
myApplication.EventClasses.Add(flightEvents);

// Add an index to the event class to help improve performance
flightEvents.IndexSqlStatements.Add(
    "CREATE INDEX FlightEventsIndex ON MyAppSchema.FlightEvents " + 
    "( LeavingFrom, GoingTo );");

// Define a chronicle for the class
EventChronicle ec1 = 
    new EventChronicle(flightEvents, "FlightEventChonicle");
ec1.SqlStatements.Add(
    "CREATE TABLE MyAppSchema.FlightEventChronicle " + 
    " (LeavingFrom nvarchar(6), GoingTo nvarchar(6), " +  
    " Price float);");
ec1.SqlStatements.Add(
    "CREATE INDEX FlightEventChronicleIndex  " + 
    "ON MyAppSchema.FlightEventChronicle " + 
    "( LeavingFrom, GoingTo );");
flightEvents.EventChronicles.Add(ec1);

// Define the event chronicle rule
EventChronicleRule ec1Rule = 
    new EventChronicleRule(flightEvents, 
    "FlightEventChronicleRule");
ec1Rule.Action = "INSERT MyAppSchema.FlightEventChronicle " + 
    " (LeavingFrom, GoingTo, Price) " + 
    " SELECT LeavingFrom, GoingTo, Price " + 
    " FROM MyAppSchema.FlightEvents;";
ec1Rule.ActionTimeout = new TimeSpan(0, 1, 20);
flightEvents.EventChronicleRule = ec1Rule;
Dim flightEvents As EventClass = _
    New EventClass(myApplication, "FlightEvents")

flightEvents.FileGroup = "PRIMARY"

' Add an orgin field to the end of the field collection.
Dim eventOrgin As EventField = _
    New EventField(flightEvents, "LeavingFrom")
eventOrgin.Type = "nvarchar(6)"
eventOrgin.TypeModifier = "not null"
flightEvents.EventFields.Add(eventOrgin)

' Define a price field and add it at position 1.
Dim eventPrice As EventField = _
    New EventField(flightEvents, "Price")
eventPrice.Type = "float"
flightEvents.EventFields.Add(eventPrice, 1)

' Define a destination field and add it before the Price field.
Dim eventDestination As EventField = _
    New EventField(flightEvents, "GoingTo")
eventDestination.Type = "nvarchar(6)"
flightEvents.EventFields.Add(eventDestination, "Price")

' Add the event class to the application
myApplication.EventClasses.Add(flightEvents)

' Add an index to the event class to help improve performance.
flightEvents.IndexSqlStatements.Add( _
    "CREATE INDEX FlightEventsIndex " + _
    "ON MyAppSchema.FlightEvents " + _
    "( LeavingFrom, GoingTo );")

' Define a chronicle for the class.
Dim ec1 As EventChronicle = _
    New EventChronicle(flightEvents, "FlightEventChonicle")
ec1.SqlStatements.Add( _
    "CREATE TABLE MyAppSchema.FlightEventChronicle " + _
    " (LeavingFrom nvarchar(6), GoingTo nvarchar(6), " + _
    " Price float);")
ec1.SqlStatements.Add( _
    "CREATE INDEX FlightEventChronicleIndex " + _
    "ON MyAppSchema.FlightEventChronicle " + _
    "( LeavingFrom, GoingTo );")
flightEvents.EventChronicles.Add(ec1)

' Define the event chronicle rule
Dim ec1Rule As EventChronicleRule = _
    New EventChronicleRule(flightEvents, _
        "FlightEventChronicleRule")
ec1Rule.Action = _
    "INSERT MyAppSchema.FlightEventChronicle " + _
    " (LeavingFrom, GoingTo, Price) " + _
    " SELECT LeavingFrom, GoingTo, Price " + _
    " FROM MyAppSchema.FlightEvents;"
ec1Rule.ActionTimeout = New TimeSpan(0, 1, 20)
flightEvents.EventChronicleRule = ec1Rule

スレッド セーフ

この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

EventClass Members
Microsoft.SqlServer.Management.Nmo Namespace

その他の技術情報

イベント クラスの定義
EventClass 要素 (ADF)