在 SQL Server Management Studio 中调试存储过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2016879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging stored procedures in SQL Server Management Studio
提问by Nick
Is there a way to step into the stored procedure code in 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
有没有办法进入 SQL Server Management Studio 中的存储过程代码?我知道这在 Visual Studio 中是可能的,但我正在从 Management Studio 中寻找可靠的调试解决方案
采纳答案by Remus Rusanu
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:StmtCompletedevent, which is not exactly debugger step-by-step, but at least you'll see the execution flow. Not to be done on a production machine, obviously.
在 2005 年,唯一的方法是附加 Profiler 并监视SP:StmtCompleted事件,这不是逐步调试器,但至少您会看到执行流程。显然,不能在生产机器上完成。
回答by Doug
I have written a pretty detailed blog post about it here:
我在这里写了一篇非常详细的博客文章:
Basically the gist of it is that you enter your sql query to execute your stored procedure, and instead of pressing F5or hitting the exclamation, you hit the play button and use F10and F11to step through and step into your stored procs.
基本上它的要点是你输入你的 sql 查询来执行你的存储过程,而不是按下F5或点击感叹号,你点击播放按钮并使用F10和 单F11步执行并进入你的存储过程。
This is very handy but no one seems to use it.
这非常方便,但似乎没有人使用它。
回答by Nick Kavadias
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。
回答by Rob Farley
Watch out for debugging stored procedures using 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.
注意使用 Visual Studio 调试存储过程。实现这一点的方法是使用大量的锁定,因此您永远不应该在生产系统上这样做。
回答by marc_s
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 2008for details - it also deals with debugging (towards the end of the article).
有关详细信息,请参阅这篇出色的文章SQL Server 2008 中的管理工作室改进- 它还涉及调试(在文章末尾)。
回答by Adam Caviness
Please be aware when debugging remote instances with SSMS that your server and client firewall will need to allow sqlservr.exe and ssms.exe respectively, along with tcp port 135. The client firewall in my particular case was causing a "timeout expired" when attempting to debug.
请注意,在使用 SSMS 调试远程实例时,您的服务器和客户端防火墙将需要分别允许 sqlservr.exe 和 ssms.exe 以及 tcp 端口 135。在我的特定情况下,客户端防火墙在尝试时导致“超时过期”调试。