6

In a C# VisualStudio project the C# code calls a stored procedure which is referenced in the .dbml file (or the procedure is called via a SQL command from C#).

Is it possible to set a break point in the stored procedure code and get a break there whenever the stored procedure is called from a C# debug session (like it is possible by right clicking on the stored procedure in the SQL Server Object Explorer an choose "Debug Procedure")?

5
  • are you facing any problem in debugging it from SQL Server? what is making you to debug it from Visual Studio. Commented Dec 21, 2016 at 11:57
  • You can't debug it from Visual Studio. Commented Dec 21, 2016 at 12:01
  • No, you can - from SQL Server Object Explorer. Commented Dec 21, 2016 at 12:03
  • @NMathur - I like the comfort to do everything from one application if it is possible... but this is not the problem. Commented Dec 21, 2016 at 12:04
  • I only know one method .. execute the procedure . pass values and then debug .... but its good to trying new ways .. not sure if it is possible . but good luck .. Commented Dec 21, 2016 at 12:11

1 Answer 1

4

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

Read and follow the guide "How to debug stored procedures in Visual Studio .NET (Option 2)"

Here are the pertinent steps from this article...

  1. 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.

  2. Set a breakpoint on the line of code that executes the stored procedure.

  3. In Server Explorer, locate and open the stored procedure. Right-click the stored procedure and then click Edit Stored Procedure.

  4. Set a breakpoint in the stored procedure on the SELECT statement, which is the only line of executable code.

  5. Run the project.

  6. Perform the action that triggers the code that calls the stored procedure.

  7. Press F11. Code execution steps from the ExecuteReader method into the stored procedure window.

N.B. I'm not an expert in this as I prefer to use SSMS.

Sign up to request clarification or add additional context in comments.

3 Comments

That works! Here is just one strange problem: I've to start one manual stored procedure debug session per VisualStudio session and then I can set the break point in every procedure everywhere. (Point 4 does nothing here - also it is not necessary to set a break point in the C# code (Point 2)).
"Set a breakpoint in the stored procedure on the SELECT statement, which is the only line of executable code" - is there any way to do this if the SP is not part of the project, but already exists in the SQLS DB?
@MauryMarkowitz try this article for more information - codeproject.com/Articles/1079275/…. I still don't use this myself.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.