CONTEXT THE SQLCONTEXT CLASS In SQL Server 2005 when

CONTEXT THE SQLCONTEXT CLASS In SQL Server 2005 when you use .NET to write procedures, functions, and triggers, you no longer need to explicitly create the connections, as was necessary when writing extended stored procedures. SQL Server 2005 and the CLR do this by introducing a class called SqlContext. So how does this work? Remember that we mentioned contexts in the beginning of this section namely, that we have contexts when connecting, executing, and doing other things in the database? You can see the SqlContextas a helper class first retrieve the particular context the caller runs under and from there the managed representations of SQL Server objects: connections, commands, and so on. The managed representations of the different contexts are exposed as classes, and they are based on the caller s context, which has been abstracted into SqlContext. To get the different classes, you use static factory methods in SqlContext. Table 4-1 lists these methods and the respective classes. Some of the classes are probably familiar to you, whereas others are new. You can instantiate some of the classes in Table 4-1 SqlCommand, for example by using a constructor (New in VB.NET), but normally you would use the methods listed in the table, and we will cover those later in this chapter. You can create the other classes that are part of the SqlServer provider in the same way that you normally would create them if used from ADO.NET. By now you may be wondering: If some of the managed classes are calling into SQL Server, does that mean that the internals of SQL Server are managed as well, and if not, are interoperability calls between managed and native code space happening? The answers are no and yes. No, the internals of SQL Server are not managed Microsoft did not rewrite the Table 4-1: SqlContext Methods Method Component Class GetConnection() Connection SqlConnection GetCommand() Command SqlCommand GetTransaction() Transaction SqlTransaction GetPipe() Pipe SqlPipe GetTriggerContext() TriggerContext SqlTriggerContext

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Bookmark the permalink.

Comments are closed.