SqlPipe 類別

定義

允許 SQL Server 資料庫上同處理序 (In-Process) 執行的 Managed 預存程序 (Stored Procedure) 將結果傳回呼叫端。 此類別無法獲得繼承。

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

範例

下列範例會使用 SqlConnectionSqlCommand 從預存程式中的資料來源中選取資料列。 然後,此範例會使用 SqlPipe 來執行 命令,並將結果傳回用戶端。

[Microsoft.SqlServer.Server.SqlProcedure()]
public static void StoredProcExecuteCommand(int rating)
{
    // Connect through the context connection.
    using (SqlConnection connection = new SqlConnection("context connection=true"))
    {
        connection.Open();

        SqlCommand command = new SqlCommand(
            "SELECT VendorID, AccountNumber, Name FROM Purchasing.Vendor " +
            "WHERE CreditRating <= @rating", connection);
        command.Parameters.AddWithValue("@rating", rating);

        // Execute the command and send the results directly to the client.
        SqlContext.Pipe.ExecuteAndSend(command);
    }
}
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub StoredProcExecuteCommand(ByVal rating As Integer)
    Dim command As SqlCommand

    ' Connect through the context connection
    Using connection As New SqlConnection("context connection=true")
        connection.Open()

        command = New SqlCommand( _
            "SELECT VendorID, AccountNumber, Name FROM Purchasing.Vendor " & _
            "WHERE CreditRating <= @rating", connection)
        command.Parameters.AddWithValue("@rating", rating)

        ' Execute the command and send the results directly to the client
        SqlContext.Pipe.ExecuteAndSend(command)
    End Using
End Sub

備註

這個類別的實例可透過 Pipe 類別的 SqlContext 屬性提供給 Managed 預存程式。

屬性

IsSendingResults

取得值,指出 SqlPipe 是否處於將單一結果集 (Result Set) 傳送回用戶端的模式。 這個屬性是唯讀的。

方法

ExecuteAndSend(SqlCommand)

執行做為參數傳遞的命令,並將結果傳送至用戶端。

Send(SqlDataReader)

將多資料列結果集直接傳送至用戶端或目前的輸出消費者。

Send(SqlDataRecord)

將單一資料列結果集直接傳送至用戶端或目前的輸出消費者。

Send(String)

將字串訊息直接傳送至用戶端或目前的輸出消費者。

SendResultsEnd()

標記結果集的結尾,並將 SqlPipe 執行個體返回初始狀態。

SendResultsRow(SqlDataRecord)

將資料的單一資料列傳送回用戶端。

SendResultsStart(SqlDataRecord)

標記要傳送回用戶端之結果集的開頭,並使用這個 record 參數,建構描述結果集的中繼資料。

適用於