SqlContext クラス
アセンブリ: System.Data (system.data.dll 内)
構文
解説
SqlContext オブジェクトを使用すると、(トリガ内で実行されているコードの) トリガ コンテキストや、(ストアド プロシージャなどで利用可能な場合) パイプ オブジェクトを取得できます。また、クライアントが統合認証を通じて認証されている場合は、このクラスを使用して、呼び出し元クライアントの Microsoft Windows ID を表す WindowsIdentity オブジェクトを取得できます。
次の例では、新しい SqlDataRecord と、その SqlMetaData オブジェクトを作成します。さらに、SendResultsStart メソッドで結果セットの先頭を宣言し、サンプルのデータを含むレコードを、SendResultsRow メソッドでクライアントに返した後、結果セットの最後に到達したことを、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
[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.SqlContext
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- SqlContext クラスのページへのリンク