HowTo: Debug a Managed Stored Procedure with Visual Studio 2005 and SQL Server 2005

In response to a newsgroup post, I wrote this quick little tutorial.

This tutorial assumes you have the AdventureWorks database installed, but any database will do.

1. Create SQL Server Project in Visual Studio

2. Add a connection to AdventureWorks database when prompted for a connection.

3. Add a new item to the project, new Stored Procedure, name: uspHellowWorld.cs

4. add the following code to uspHelloWorld():

    SqlContext .GetPipe().Send("Hello World" );

5. Deploy the project (right click on the product, select Deploy)

6. In the Server Explorer window, right click on the Data Connection to the AdventureWorks database, select "Allow SQL/CLR Debugging". CLick YES to the message that says "SQL/CLR debugging will cause all managed threads on the server to be stopped. Do you want to continue?"

7. Set a break point on the code created in step 4.

8. Press F5 to start debugging. You should see that your project will get re-deployed, then vs debugging will startup and your breakpoint should be hit.

 

This is about as simple as it gets.

 

j.