Ajax toolkit
Ajax tutorials
4.7. ADO.NET In-Process Extensions Supporting CLR ProgrammingADO.NET has four main in-process functional extensions that are used when programming .NET Framework routines. The SqlContext object provides access to context information, to a SqlPipe object for sending results to the client, and to a SqlTriggerContext object that provides information about the operation that caused a trigger to fire. The fourththe SqlDataRecord objectreturns to the caller a custom result set from a stored procedure. These four extensions are discussed in the following subsections. 4.7.1. SqlContext ObjectManaged code is invoked in the server whenever a CLR routine is executed. Code running on the server executes in the context of the caller connection, so the CLR code needs access to the caller context. The SqlContext class in the Microsoft.SqlServer.Server namespace abstracts the context of the caller and provides access to the context components through its public static properties, described in Table 4-12.
You obtain an in-process connection using the new connection context connection string keyword. For example:
SqlConnection conn = new SqlConnection("context connection=true")
4.7.2. SqlPipe ObjectUse the SqlPipe object to send messages and result sets from a CLR stored procedure to the calling client. The SqlPipe object cannot be directly instantiated. You obtain the SqlPipe object using the Pipe property of the SqlContext object within the body of a CLR routine, as shown in the "Hello World Example" section earlier in this chapter. The SqlPipe class has the public properties and methods described in Table 4-13. 4.7.3. SqlTriggerContext ObjectThe SqlTriggerContext class provides context information about the CLR DML or DDL trigger. The SqlTriggerContext object cannot be directly instantiated. You obtain the SqlTrigger object using the triggerContext property of the SqlContext object within the body of a CLR trigger. The SqlTriggerContext class has the public properties and methods described in Table 4-14.
4.7.4. SqlDataRecord ObjectThe SqlDataRecord class represents a single row of data together with its metadata. The class allows stored procedures to return custom result sets to the client using the Send( ) or SendResultsRow( ) methods of the SqlPipe object. You instantiate a SqlDataRecord object by passing to the constructor a SqlMetaData object array that contains an element of metadata for each column in the row. Each SqlMetaData object defines a column name, column type, and possibly other column attributes. For example, the following code defines a SqlDataRecord containing two columns:
SqlMetaData[] md = new SqlMetaData[2];
md[0] = new SqlMetaData("intCol", SqlDbType.Int);
md[1] = new SqlMetaData("stringCol", SqlDbType.NVarChar, 50);
SqlDataRecord row = new SqlDataRecord(md);
The SqlDataRecord class has accessor methods that let you get and set column values. This is similar to a DataReader except that you can write column values in addition to reading them. For example, the following code fills the two columns in the SqlDataRecord object defined in the preceding example:
row.SetSqlInt32(0, 1);
row.SetSqlString(1, "Record 1");
|
Ajax toolkit
Ajax tutorials