Share via


Visual Basic .NET で警告を作成する方法

このセクションでは、パフォーマンス条件によってトリガされる、オペレータへの通知を行う警告を Visual Basic .NET で作成する方法について説明します。

コード例では、パフォーマンス条件によってトリガされる警告を作成しています。条件は、次の形式で指定する必要があります。

ObjectName|CounterName|Instance|ComparisionOp|CompValue

警告の通知にはオペレータが必要です。operator は Visual Basic キーワードであるため、Operator 型には角かっこが必要です。

警告の作成

  1. Visual Studio 2005 を起動します。

  2. [ファイル] メニューの [新規作成] をポイントして [プロジェクト] をクリックします。[新しいプロジェクト] ダイアログ ボックスが表示されます。

  3. [プロジェクトの種類] ペインで、[Visual Basic] をクリックします。[テンプレート] ペインで、[コンソール アプリケーション] をクリックします。

  4. (省略可) [名前] ボックスに新しいアプリケーションの名前を入力します。

  5. [OK] をクリックすると、Visual Basic コンソール アプリケーション テンプレートが読み込まれます。

  6. [プロジェクト] メニューの [参照の追加] をクリックします。[参照の追加] ダイアログ ボックスが表示されます。[参照] をクリックして、C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies フォルダ内で SMO アセンブリを探します。次のファイルを選択します。

    Microsoft.SqlServer.ConnectionInfo.dll

    Microsoft.SqlServer.Smo.dll

    Microsoft.SqlServer.SqlEnum.dll

    Microsoft.SqlServer.SmoEnum.dll

  7. [表示] メニューの [コード] をクリックします。または、[Module1.vb] ウィンドウをクリックしてコード ウィンドウを表示します。

  8. コードでは、宣言の前に、次の Imports ステートメントを入力し、SMO 名前空間の型を修飾します。

    Imports Microsoft.SqlServer.Management.Smo
    Imports Microsoft.SqlServer.Management.Common
    Imports Microsoft.SqlServer.Management.Smo.Agent
    
  9. このプロシージャの後に続くコードをメイン プログラムに挿入します。

  10. アプリケーションを実行およびビルドします。

使用例

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Define an Alert object variable by supplying the SQL Agent and the name arguments in the constructor.
Dim al As Alert
al = New Alert(srv.JobServer, "Test_Alert")
'Specify the performance condition string to define the alert.
al.PerformanceCondition = "SQLServer:General Statistics|User Connections||>|3"
'Create the alert on the SQL Agent.
al.Create()
'Define an Operator object variable by supplying the SQL Agent and the name arguments in the constructor.
Dim op As [Operator]
op = New [Operator](srv.JobServer, "Test_Operator")
'Set the net send address.
op.NetSendAddress = "NetworkPC"
'Create the operator on the SQL Agent.
op.Create()
'Run the AddNotification method to specify the operator is notified when the alert is raised.
al.AddNotification("Test_Operator", NotifyMethods.NetSend)

参照

概念

SQL Server エージェントでの自動管理タスクのスケジュール設定

その他の技術情報

警告の表示、変更、削除

ヘルプおよび情報

SQL Server 2005 の参考資料の入手