O'Reilly logo

Programming Microsoft® SQL Server™ 2008 by Leonard Lobel, Andrew Brust, and Stephen Forte

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Putting It All Together

Let’s end this chapter with one example that sums up the whole SQL CLR transaction story. We’ll take the SQL CLR stored procedure we wrote and call it from a console application. Inside the console application, we will wrap the SQL CLR stored procedure and the RM we wrote earlier in this chapter in a single transaction, bound together with a single System.Transactions.TransactionScope.

Because we are using only a context connection in our SQL CLR stored procedure, let’s follow the best practice of not using TransactionScope inside the SQL CLR stored procedure. The SQL CLR stored procedure should look like this:

[Microsoft.SqlServer.Server.SqlProcedure] public static void InsertRow() { using (SqlConnection contextConn = new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required