57.1. SQL-CLR Database Project

In the New Project dialog inside either Visual Basic or C# is a Database node that contains the "SQL Server Project." It's used to create managed classes to use inside a SQL Server. When you create a new project of this type, you will be prompted for a connection and to enable CLR debugging. Use CLR debugging only on development database servers and isolated from other developers as explained later in the "Best Practices" section.

There's another way to get to the SQL Server Projects, and this is located in Database Projects/Microsoft SQL Server/SQL-CLR. There you will select the flavor according to your language. You will see the projects inside the Database Projects node in the Offline Database Schema section.

You can add to this project some types like Aggregates, User-Defined Functions, Stored Procedures, Triggers, User-Defined Types, and Classes. You can think of this as a normal VB/C# project; you can add classes, references, and even web references. You can create unit tests for your methods as explained in Chapter 20, refactor your code, and build, in the same way you would for other library projects. However, the debugging history is a bit different, since your code is running in an SQL Server context. First you will need to allow VS to remote debug the code. This is needed only the first time you debug your project. However, the point of entry for your code will be through a script that will use any of your managed objects. As you may have ...

Get Professional Visual Studio® 2008 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.