SqlContext Classe

Definizione

Rappresenta un'astrazione del contesto del chiamante, che fornisce accesso agli oggetti SqlPipe, SqlTriggerContext e WindowsIdentity. La classe non può essere ereditata.

public ref class SqlContext sealed
public sealed class SqlContext
type SqlContext = class
Public NotInheritable Class SqlContext
Ereditarietà
SqlContext

Esempio

Nell'esempio seguente viene creato un nuovo SqlDataRecord oggetto e il relativo SqlMetaDataoggetto . L'esempio contrassegna quindi l'inizio di un set di risultati usando il SendResultsStart metodo , invia i record con i dati di esempio al client usando il SendResultsRow metodo e contrassegna la fine del set di risultati con il SendResultsEnd metodo .

[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

Commenti

L'oggetto SqlContext può essere usato per ottenere il contesto del trigger (per l'esecuzione del codice in un trigger) e l'oggetto pipe (se disponibile, ad esempio nelle stored procedure). Può essere usato anche per ottenere un WindowsIdentity oggetto che rappresenta l'identità di Microsoft Windows del client chiamante, se il client è autenticato con il server usando l'autenticazione integrata.

Proprietà

IsAvailable

Specifica se il codice chiamante viene eseguito in SQL Server e se è possibile accedere alla context connection.

Pipe

Ottiene l'oggetto pipe che consente al chiamante di restituire al client gruppi di risultati, messaggi e i risultati dell'esecuzione dei comandi.

TriggerContext

Ottiene il contesto del trigger utilizzato per fornire al chiamante informazioni sull'evento che ha provocato l'attivazione del trigger e una mappa delle colonne aggiornate.

WindowsIdentity

Identità Microsoft Windows del chiamante.

Si applica a