如何从C#调试会话调试存储过程? [英] How to debug stored procedures from a C# debug session?

查看:67
本文介绍了如何从C#调试会话调试存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#VisualStudio项目中,C#代码调用在.dbml文件中引用的存储过程(或通过C#中的SQL命令调用该过程).

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#).

是否有可能在C#调试会话中调用存储过程时在存储过程代码中设置断点并在那里获得中断(例如可以通过在SQL Server对象资源管理器中右键单击存储过程来实现)选择调试过程")?

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

推荐答案

要在.NET应用中进行调试时,允许您在SQL Server上逐步执行T-SQL存储过程,您需要:

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

阅读并遵循指南"如何在Visual Studio .NET中调试存储过程(选项2)"

这是本文中的相关步骤...

Here are the pertinent steps from this article...

  1. 在解决方案资源管理器中,右键单击项目(不是解决方案),然后打开属性"页面.在树中单击配置属性"然后单击以选中"SQL Server调试"复选框.调试页面以启用存储过程调试.

  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.

在执行存储的代码行上设置断点程序.

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

在服务器资源管理器中,找到并打开存储过程.右键单击存储过程,然后单击编辑存储"程序.

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

在SELECT语句的存储过程中设置一个断点,这是可执行代码的唯一一行.

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

运行项目.

执行触发调用已存储代码的代码的操作程序.

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

按F11键.代码执行步骤从ExecuteReader方法转换为存储过程窗口.

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

NB ,我不是专家,因为我更喜欢使用SSMS.

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

这篇关于如何从C#调试会话调试存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆