SqlContext 클래스

정의

SqlPipe, SqlTriggerContextWindowsIdentity 개체에 대한 액세스를 제공하는 호출자 컨텍스트의 추상화를 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class SqlContext sealed
public sealed class SqlContext
type SqlContext = class
Public NotInheritable Class SqlContext
상속
SqlContext

예제

다음 예제에서는 새 SqlDataRecordSqlMetaData입니다. 예제는 다음 결과 사용 하 여 집합의 시작을 표시 합니다 SendResultsStart 메서드를 사용 하 여 클라이언트에 다시 예제 데이터를 사용 하 여 레코드를 보냅니다 합니다 SendResultsRow 메서드를 사용 하 여 결과의 끝 설정 표시를 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입니다.

적용 대상