如何监控 SQL Server 2005 上执行的 sql 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47376/
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
How can I monitor the executed sql statements on a SQL Server 2005
提问by sven
In a project of mine the SQL statements that are executed against a SQL Server are failing for some unknown reason. Some of the code is already used in production so debugging it is not an easy task. Therefore I need a way to see in the database itself what SQL statements are used, as the statements are generated at runtime by the project and could be flawed when certain conditions are met.
在我的一个项目中,针对 SQL Server 执行的 SQL 语句由于某种未知原因而失败。一些代码已经在生产中使用,因此调试不是一件容易的事。因此,我需要一种方法来查看数据库本身使用了哪些 SQL 语句,因为这些语句是由项目在运行时生成的,并且在满足某些条件时可能存在缺陷。
I therefore considered the possibility to monitor the incoming statements and check myself if I see any flaws.
因此,我考虑了监控传入报表并检查自己是否发现任何缺陷的可能性。
The database is running on a SQL Server 2005, and I use SQL server management studio express as primary tool to manipulate the database. So my question is, what is the best way to do this?
数据库在 SQL Server 2005 上运行,我使用 SQL server management studio express 作为主要工具来操作数据库。所以我的问题是,这样做的最佳方法是什么?
回答by Erik van Brakel
Seeing how you use the Management Studio Express, I will assume you don't have access to the MSSQL 2005 client tools. If you do, install those, because it includes the SQL profiler which does exactly what you want (and more!). For more info about that one, see msdn.
看到您如何使用 Management Studio Express,我将假设您无权访问 MSSQL 2005 客户端工具。如果您这样做,请安装它们,因为它包含 SQL 探查器,它可以完全满足您的需求(甚至更多!)。有关该的更多信息,请参阅msdn。
I found thisa while ago, because I was thinking about the exact same thing. I have access to the client tools myself, so I don't really need to yet, but that access is not unlimited (it's through my current job). If you try it out, let me know if it works ;-)
不久前我发现了这个,因为我正在考虑完全相同的事情。我自己可以访问客户端工具,所以我现在还不需要,但这种访问不是无限制的(这是通过我目前的工作)。如果您尝试一下,请告诉我它是否有效;-)
回答by SQLMenace
Best way is to fire up profiler, start a trace, save the trace and then rerun the statements
最好的方法是启动分析器,开始跟踪,保存跟踪,然后重新运行语句