The CLR is the execution environment provided by the
Microsoft .NET Framework. It is likely that you had to install the .NET
Framework at one time or another, usually as a prerequisite for
installing an application. The .NET Framework is a new-generation
application platform, and many modern applications, including SQL
Server, use it as the execution environment. The .NET Framework
provides developers with the ability to compile applications written in
a .NET-compliant language. The .NET Framework serves as runtime for
these applications. Figure 1 shows the key components of the .NET Framework.
Figure 1. The .NET Framework
.NET Framework is installed on an operating system and is used to
access the operating system’s services during runtime. There is a
version of the .NET Framework for 32-bit and 64-bit Windows platforms,
as well as some other operating systems like Windows CE and Windows
Mobile. Application services exposed by applications like SQL Server,
IIS, WMI, COM+, and many more are available to the developer through
the .NET Framework. The Base Class Library provides commonly used
functionality to developers in the form of classes and namespaces. We
will examine the Base Class Library in more detail later in this
usually use the Visual Studio .NET Integrated Development Environment
(IDE) to create .NET applications. However, the IDE is not absolutely
necessary, and it is possible to create simple text source code files
and compile them using a .NET compiler. You can create .NET
applications in any .NET-compliant language to suit the specific
functionality you wish to implement. Over 60 major language families
are available for the .NET Framework, each with many variants and
branches. The most popular .NET languages are C# and Visual Basic .NET.
Support for these languages is available out-of-the-box when you
install Visual Studio .NET.
.NET Framework includes a compiler component for each .NET-compliant
language. This component compiles the source code written in the
specific high-level language to the lower-level Microsoft Intermediate
Language (MSIL). When the application is running, the CLR translates
MSIL to native machine instructions. This is done by a component known
as just-in-time (JIT) compilation. It is important to understand that
no matter which .NET language you develop your application in, it will
be compiled to the one common language—MSIL. This is from where the
word common in Common Language Runtime originates.
CLR is responsible for executing MSIL code. The CLR also manages the
code that runs within it by providing the code with runtime services. Figure 2 outlines some of the services provided by the CLR.
Figure 2. Common Language Runtime Services
CLR manages code execution by providing mandatory stability and
security-checking engines, as well as resource management. For example,
the Garbage Collection service provided by the CLR ensures optimal
memory management. Thread management provides parallel processing
capabilities. The Base Class Library support, error management, and
debugging services create a consistent development environment for all
Code that runs within the CLR is known as managed code,
as the CLR provides it with management services like those mentioned
above. The term is often used to distinguish between .NET code and
native code (for example, code written using Visual Basic 6 or C++).
Native code runs outside the CLR and is referred to as unmanaged code.
Unmanaged code is not subject to CLR services, like code access
security. Within SQL Server, all objects that use CLR integration are
written as managed code. Extended stored procedures (XPs) are unmanaged
code and are written using C++.
Additionally, XPs are deprecated, and support for this feature is likely to be removed in future versions of SQL Server.
CLR abstracts essential services such as memory and security management
away from developers, allowing them to concentrate on the specific
functionality of their code.
Server 2008 supports assemblies targeted at .NET Framework 2.0 or
later. During installation of SQL Server 2008, .NET Framework 2.0
Service Pack 1 will be installed automatically. SQL Server 2008 does
not support assemblies targeted at .NET Framework 1.0 and .NET
Studio 2008 is the latest version of Visual Studio—the Microsoft IDE
used to create .NET Framework applications. Visual Studio 2008 can be
used to create a variety of applications, and one of the key new
features is support for Language Integrated Query (LINQ). Both Visual
Studio 2005 and Visual Studio 2008 can be used to create assemblies
containing CLR objects for SQL Server 2008 CLR integration. Visual
Studio 2003 and Visual Studio .NET 2001 cannot be used.