THE IN-PROCESS DATA PROVIDER Client Connection SqlServer.exe Plnvoke

THE IN-PROCESS DATA PROVIDER Client Connection SqlServer.exe Plnvoke SqlCommand cmd= SqlContext.GetCommand(); cmd.ExecuteNonQuery(); Managed Code Unmanaged Code Figure 4-3: Interop to Retrieve the SQL Context whole of SQL Server in managed code. And yes, interoperability calls happen. The managed classes are making PInvoke calls against the executable of SQL Server, sqlservr.exe, as shown in Figure 4-3, which exposes a couple of dozen methods for the CLR to call into. When you read about interop, you may become concerned about performance. Theoretically, a performance hit is possible, but because SQL Server hosts the CLR (as discussed in Chapter 2) and the SqlServer provider runs in process with SQL Server, the hit is minimal. In the last sentence, notice that we said theoretically: Remember that when you execute CLR code, you will run machine-compiled code, which is not the case when you run T-SQL. Therefore, for some code executing in the CLR, the end result may be a performance improvement, compared with pure T-SQL code. Now, that we have discussed the SqlContextclass, let s see how we go about using it. Connections As already mentioned, when you are at server side and a client executes, you are part of that client s connection context, which in the SQL Server 2005 release is exposed through the static GetConnection method in the SqlContext class. So rather than creating a new connection (as is necessary with a connection from within extended stored procedures), you call SqlContext.GetConnection, as shown in the following code snippet.

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.