Implementing Managed code in SQL Server 2005 using Visual Studio.NET 2005
(Page 1 of 5 )
This article starts with an introduction to "CLR integration to SQL Server 2005." It further proceeds with creation and execution of Managed code using Visual Studio.NET 2005 beta.
Supplemental files for this article can be found here.
Introduction to CLR (Common Language Runtime)
The common language runtime (CLR) is the heart of the Microsoft .NET Framework and provides the execution environment for all .NET Framework code. Code that runs within the CLR is referred to as managed code. The CLR provides various functions and services required for program execution, including just-in-time (JIT) compilation, allocating and managing memory, enforcing type safety, exception handling, thread management, and security.
One of the benefits of managed code is type safety, or the assurance that code accesses types only in well-defined, permissible ways. Before managed code is executed, the CLR verifies that the code is safe. For example, the code is checked to ensure that no memory is read that has not previously been written. The CLR can also help ensure that code does not manipulate unmanaged memory.
Microsoft SQL Server 2005 (Yukon) now features the integration of the common language runtime (CLR) component of the .NET Framework for Microsoft Windows. The CLR supplies managed code with services such as cross-language integration, code access security, object lifetime management, and debugging and profiling support. For SQL Server users and application developers, CLR integration means that you can now write stored procedures, triggers, user-defined types, and user-defined functions using any .NET Framework language, including Microsoft Visual Basic .NET and Microsoft Visual C#.
SQL Server 2005 essentially acts as the operating system for the CLR when it is hosted inside SQL Server 2005. The CLR calls low-level routines implemented by SQL Server 2005 for threading, scheduling, synchronization, and memory management. These are the same primitives that the rest of the SQL Server 2005 engine uses.
In previous versions of SQL Server, database programmers were limited to using T-SQL when writing code on the server side. With CLR integration, database developers can now perform tasks that were impossible or difficult to achieve with T-SQL alone. Both Visual Basic .NET and C# offer full support for arrays, structured exception handling, and collections. With these languages, developers can leverage CLR integration to write code that has more complex logic and is more suited for computation tasks. Visual Basic .NET and C# offer object-oriented capabilities such as encapsulation, inheritance, and polymorphism. Related code can now be easily organized into classes and namespaces.
The next topic covers "Managed Code" and explains the ways in which it is different from "Un-Managed Code."
Next: Introduction to Managed Code >>
More MS SQL Server Articles
More By Jagadish Chaterjee