SqlContext クラス

定義

呼び出し元のコンテキストを抽象化し、SqlPipeSqlTriggerContextWindowsIdentity の各オブジェクトへのアクセスを提供します。 このクラスは継承できません。

public ref class SqlContext sealed
public sealed class SqlContext
type SqlContext = class
Public NotInheritable Class SqlContext
継承
SqlContext

次の例では、新 SqlDataRecord しい とその を作成します SqlMetaData。 次に、 メソッドを使用して結果セットの先頭をマークし、 メソッドを使用してSendResultsStartSendResultsRowサンプル データを含むレコードをクライアントに送り返し、結果セットの末尾を メソッドでSendResultsEndマークします。

[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcReturnResultSet()
{
    // Create the record and specify the metadata for the columns.
    SqlDataRecord record = new SqlDataRecord(
        new SqlMetaData("col1", SqlDbType.NVarChar, 100),
        new SqlMetaData("col2", SqlDbType.Int));

    // Mark the begining of the result-set.
    SqlContext.Pipe.SendResultsStart(record);

    // Send 10 rows back to the client.
    for (int i = 0; i < 10; i++)
    {
        // Set values for each column in the row.
        record.SetString(0, "row " + i.ToString());
        record.SetInt32(1, i);

        // Send the row back to the client.
        SqlContext.Pipe.SendResultsRow(record);
    }

    // Mark the end of the result-set.
    SqlContext.Pipe.SendResultsEnd();
}
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub StoredProcReturnResultSet()

    ' Create the record and specify the metadata for the columns.
    Dim record As New SqlDataRecord( _
        New SqlMetaData("col1", SqlDbType.NVarChar, 100), _
        New SqlMetaData("col2", SqlDbType.Int))

    ' Mark the begining of the result-set.
    SqlContext.Pipe.SendResultsStart(record)

    ' Send 10 rows back to the client.
    Dim i As Integer
    For i = 0 To 9

        ' Set values for each column in the row.
        record.SetString(0, "row " & i.ToString())
        record.SetInt32(1, i)

        ' Send the row back to the client.
        SqlContext.Pipe.SendResultsRow(record)
    Next

    ' Mark the end of the result-set.
    SqlContext.Pipe.SendResultsEnd()
End Sub

注釈

オブジェクトを SqlContext 使用して、トリガー コンテキスト (トリガーで実行されるコードの場合) とパイプ オブジェクト (ストアド プロシージャ内など) を取得できます。 また、統合認証を WindowsIdentity 使用してクライアントがサーバーで認証されている場合は、呼び出し元クライアントの Microsoft Windows ID を表すオブジェクトを取得するためにも使用できます。

プロパティ

IsAvailable

呼び出し元コードを SQL Server 内で実行するかどうかと、コンテキスト接続にアクセスできるかどうかを示します。

Pipe

呼び出し元が、結果セット、メッセージ、およびコマンドの実行結果をクライアントに送り返すことを可能にするパイプ オブジェクトを取得します。

TriggerContext

呼び出し元に、トリガーの発生源に関する情報と、更新された列のマップを提供するトリガー コンテキストを取得します。

WindowsIdentity

呼び出し元の Microsoft Windows ID。

適用対象