SqlContext 類別

定義

表示呼叫端內容的抽象,提供對 SqlPipeSqlTriggerContextWindowsIdentity 物件的存取。 此類別無法獲得繼承。

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

範例

下列範例會建立新的 SqlDataRecord 及其 SqlMetaData 。 然後,此範例會使用 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 身分識別的 物件。

屬性

IsAvailable

指定呼叫程式碼是否在 SQL Server 中執行,且是否可存取內容連接。

Pipe

取得管道物件,允許呼叫端將結果集、訊息和執行命令的結果傳送回用戶端。

TriggerContext

取得觸發程序內容,用於向呼叫端提供何者引發觸發程序的相關資訊,以及更新之資料行的對應。

WindowsIdentity

呼叫端的 Microsoft Windows 識別。

適用於