31

I am debugging some C# code that uses Ado.net to call a stored proc (TSQL) in SQL Server. How can I step into the stored proc?

(I think I have seen this demoed by Microsoft staff, but can’t recall the 101 “magic” settings that are needed to get it to work.)

4 Answers 4

18
+50

I'll build on Davide's answer and Ian's comment to it because that was the exactly the process I have gone through.

Assumption: answer is based on VS2008 & VS2010.

To step through a T-SQL stored procedure on SQL Server while debugging a .NET app you need to do the following:

  1. Follow the MS Support instructions "How to debug stored procedures in Visual Studio .NET (Option 2)"

    • Ensure that you have enabled SQL Server debugging in the project's properties (Step 4 in the linked instructions).
    • Ensure you have set a breakpoint in the stored procedure itself (Steps 6-7)
  2. Enable the Allow SQL/CLR Debugging on the Data Connection on which the stored procedure is called:

    • (without this second step you'll be getting "The breakpoint will not currently be hit. Unable to bind SQL breakponit at this time. Object containing the breakpoint not loaded." as reported by Ian)
    • Server Explorer > Data Connections
    • Right-click on the connection that you are using in the code
    • Tick the Allow SQL/CLR Debugging option in the menu

Added from comments: (This seem to be key to getting it to work)

It works with a programmatically created connection, too. You just have to use the exact same connection string that is displayed when you right-click the server instance, click on 'Properties' and scroll down to 'Connection string' (Verbindungszeichenfolge in German).

7
  • 2
    @Ian I am afraid you have to use a connection which is listed in the Server Explorer. None of the relevant documentation nor poking around in VS itself show that it'd be possible to do so for a programmatically created connection. So at least for debug/test purposes you'd need a listed connection. Jul 26, 2011 at 20:56
  • I think "connection which is listed in the Server Explorer" is the to way this just works for some people but other people can never get it to work. Jul 27, 2011 at 9:31
  • @Ian you are probably right. I wonder if that's concious design decision or an oversight... Jul 27, 2011 at 21:00
  • NOTE: In VS 2013, step 4 of the "How to debug stored procedures in Visual Studio .NET (Option 2)" link is: under the Web section of the tree. Click Web and scroll down to the Debuggers section and you will see SQL Server there.
    – levininja
    Oct 18, 2013 at 19:50
  • 1
    @IanRingrose it works with a programmatically created connection, too. You just have to use the exact same connection string that is displayed when you right-click the server instance, click on 'Properties' and scroll down to 'Connection string' (Verbindungszeichenfolge in German). Note that, apparently, you can add an Initial Catalog at the end of that string. Feb 5, 2014 at 15:38
8

For those of you who are using VS 2012 and are confused as to why you cannot enable SQL/CLR Debugging from the Server Explorer window, you actually need to connect via the "SQL Server Object Explorer" window.

Once you have the connection in that window, the Allow SQL/CLR Debugging and Application Debugging setting appear on the right-click context menu of your server. This probably applies to 2013 as well but I cannot confirm.

2
  • 1
    I found those settings in SQL Server Object Explorer in VS 2013, but still get message that breakpoint will not currently be hit. Oct 21, 2014 at 16:16
  • Thank you! This solved the problem for me in VS 2015.
    – EM0
    Nov 3, 2015 at 13:15
1

Enable the SQL Server debugging in the project properties.

3
  • Sorry I have tied this, and Visual Studio just steps over the call to ExecuteReader(), rathern than stepping into the stored proc Jan 19, 2011 at 15:18
  • I think you need debug permission to debug into the stored procedure, does the SQL server run on your local computer?
    – J.W.
    Jan 19, 2011 at 15:26
  • 1
    @J.W If a selected a stored proc from the server explorer I can step into it. Jan 19, 2011 at 15:27
0

In Solution Explorer, right-click the project (not the solution) and open the Property pages. Click Configuration Properties in the tree and then click to select the SQL Server Debugging check box on the Debugging page to enable stored procedure debugging.

reference: http://support.microsoft.com/kb/316549

1
  • 2
    When I got to set the break point in the stored proc I get "The breakpoint will not currently be hit. Unable to bind SQL breakponit at this time. Object containing the breakpoint not loaded." Jan 19, 2011 at 15:28

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.