15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Microsoft.sqlserver.server ❘ 957<br />

figure 34-1<br />

miCrosofT.sqlserVer.serVer<br />

Chapter 30, “Core ADO.<strong>NET</strong>,” discusses classes from the namespace System.Data.SqlClient. This<br />

section discusses another namespace, the Microsoft.SqlServer.Server namespace. The Microsoft.<br />

SqlServer.Server namespace includes classes, interfaces, <strong>and</strong> enumerations specific to the .<strong>NET</strong><br />

Framework. However, many of the System.Data.SqlClient classes are also needed within server-side<br />

code as you will see.<br />

The following table lists the major classes from the Microsoft.SqlServer.Server namespace <strong>and</strong> their<br />

functionality.<br />

Class<br />

SqlContext<br />

SqlPipe<br />

SqlDataRecord<br />

SqlTriggerContext<br />

desCriPTion<br />

Like an HTTP context, the SQL context is associated with the request of a client.<br />

With static members of the SqlContext class, SqlPipe, SqlTriggerContext,<br />

<strong>and</strong> WindowsIdentity can be accessed.<br />

With the SqlPipe class, results or information can be sent to the client. This class<br />

offers the methods ExecuteAndSend(), Send(), <strong>and</strong> SendResultsRow().<br />

The Send() method has different overloads to either send a SqlDataReader,<br />

SqlDataRecord, or string.<br />

The SqlDataRecord represents a single row of data. This class is used in<br />

conjunction with SqlPipe to send or receive information from the client.<br />

The SqlTriggerContext class is used within triggers. This class provides<br />

information about the trigger that was fired.<br />

This namespace also includes several attribute classes: SqlProcedureAttribute, SqlFunctionAttribute,<br />

SqlUserDefinedAttribute, <strong>and</strong> SqlTriggerAttribute. These classes are used for deployment of stored<br />

procedures, functions, user-defined types, <strong>and</strong> triggers in SQL Server. When deploying from Visual Studio,<br />

it is required that you apply these attributes. When deploying the database objects using SQL statements,<br />

these attributes are not needed but they help, because some properties of these attributes influence the<br />

characteristics of the database objects.<br />

You see these classes in action later in this chapter when writing stored procedures <strong>and</strong> user-defined<br />

functions is discussed, but first, the following section looks into creating user-defined types with <strong>C#</strong>.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!