Chapter 34. .NET Programming with SQL Server

WHAT'S IN THIS CHAPTER?

  • Hosting the .NET runtime with SQL Server

  • Classes from the namespace System.Data.SqlServer

  • Creating user-defined types and aggregates

  • Stored procedures

  • User-defined functions

  • Triggers

  • Using XML data types

SQL Server 2005 was the first version of this database product to host the .NET runtime. In fact, it was the first new version of Microsoft's SQL Server product in nearly six years. It allows running .NET assemblies in the SQL Server process. Furthermore, it enables you to create stored procedures, functions, and data types with .NET programming languages such as C# and Visual Basic.

Note

This chapter requires a SQL Server edition hosting the CLR. This is possible with SQL Server 2005 or a later version. SQL Server 2005 and 2008 require .NET 3.5. So with the server-side projects of this chapter, the CLR version must be set to 3.5.

The samples in this chapter use a newly created SqlServerSampleDB database that you can download with the code samples and the AdventureWorks database. The AdventureWorks database is a sample database from Microsoft that you can install as an optional component with SQL Server.

SQL Server has many features that are not directly associated with the CLR, such as many T-SQL improvements, but they are not covered in this book. To get more information about these features, you can read Wrox's Professional Microsoft SQL Server 2008 Programming (Wiley Publishing, Inc., ISBN 978-0-470-25702-9).

.NET RUNTIME ...

Get Professional C# 4 and .NET 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.