简体   繁体   English

在 SQL Server Management Studio 中调试存储过程

[英]Debugging stored procedures in SQL Server Management Studio

Is there a way to step into the stored procedure code in SQL Server Management Studio?有没有办法进入 SQL Server Management Studio 中的存储过程代码? I know this is possible with Visual Studio, but I am looking for a dependable debugging solution from within Management Studio我知道这在 Visual Studio 中是可能的,但我正在从 Management Studio 中寻找可靠的调试解决方案

Only with SQL 2008 and SSMS 2008. Select from menu 'Debug\\Start Debugging' or press Alt+F5 and will launch the step by step T-SQL debugger.仅适用于 SQL 2008 和 SSMS 2008。从菜单“调试\\开始调试”中选择或按 Alt+F5 将启动逐步的 T-SQL 调试器。

On 2005 the only way is to attach Profiler and monitor for the SP:StmtCompleted event, which is not exactly debugger step-by-step, but at least you'll see the execution flow.在 2005 年,唯一的方法是附加 Profiler 并监视SP:StmtCompleted事件,这不是逐步调试器,但至少您会看到执行流程。 Not to be done on a production machine, obviously.显然,不能在生产机器上完成。

I have written a pretty detailed blog post about it here:我在这里写了一篇非常详细的博客文章:

http://www.diaryofaninja.com/blog/2010/11/23/debugging-sql-queries-function-amp-stored-procedures-with-sql-management-studio http://www.diaryofaninja.com/blog/2010/11/23/debugging-sql-queries-function-amp-stored-procedures-with-sql-management-studio

Basically the gist of it is that you enter your sql query to execute your stored procedure, and instead of pressing F5 or hitting the exclamation, you hit the play button and use F10 and F11 to step through and step into your stored procs.基本上它的要点是你输入你的 sql 查询来执行你的存储过程,而不是按F5或点击感叹号,你点击播放按钮并使用F10F11 单步执行并进入你的存储过程。

This is very handy but no one seems to use it.这非常方便,但似乎没有人使用它。

The ability to debug sprocs, which was in Query Analyzer in SQL Server 2000 was not put into SQL Server 2005. Microsoft realized this mistake and put the functionality back in in SQL Server 2008. SQL Server 2000 中的查询分析器中的调试 sprocs 的能力没有被放入 SQL Server 2005。微软意识到这个错误并将该功能放回 SQL Server 2008 中。

In SSMS 2008 you can start the debugger by either clicking the debug button on the toolbar or pressing ALT+F5.在 SSMS 2008 中,您可以通过单击工具栏上的调试按钮或按 ALT+F5 来启动调试器。

Unfortunately, running SSMS 2008 against a 2005 database will not allow you to debug, so you'll have to stick with Visual Studio.不幸的是,针对 2005 数据库运行 SSMS 2008 将不允许您进行调试,因此您必须坚持使用 Visual Studio。

Watch out for debugging stored procedures using Visual Studio.注意使用 Visual Studio 调试存储过程。 The way that this is implemented is to use an incredible amount of locking so that you should never do this on a production system.实现这一点的方法是使用大量的锁定,因此您永远不应该在生产系统上这样做。

Yes, in SSMS 2008 you can definitely step into T-SQL code (code block, stored func, stored proc) and debug it.是的,在 SSMS 2008 中,您绝对可以进入 T-SQL 代码(代码块、存储函数、存储过程)并对其进行调试。

See this excellent article Management Studio Improvements in SQL Server 2008 for details - it also deals with debugging (towards the end of the article).有关详细信息,请参阅这篇出色的文章SQL Server 2008 中的管理工作室改进- 它还涉及调试(在文章末尾)。

请注意,在使用 SSMS 调试远程实例时,您的服务器和客户端防火墙需要分别允许 sqlservr.exe 和 ssms.exe 以及 tcp 端口 135。在我的特定情况下,客户端防火墙在尝试时导致“超时过期”调试。

从 SSMS 17 开始,您不能调试任何 SQL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM