How to debug stored procedures from a C# debug session?

雨燕双飞 提交于 2021-01-27 06:54:50

问题


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")?


回答1:


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.



来源:https://stackoverflow.com/questions/41262244/how-to-debug-stored-procedures-from-a-c-sharp-debug-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!