是否有可能自动SQL Server 2008中探查? [英] Is it possible to automate SQL Server 2008 profiler?

查看:161
本文介绍了是否有可能自动SQL Server 2008中探查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个<一个href=\"http://stackoverflow.com/questions/488020/what-is-your-most-useful-sql-trick-to-avoid-writing-more-$c$c\">post关于有用的SQL技巧。在这里,我要提 SQL Server事件探查工具,因为它具有帮我少写SQL。我会写SQL,将询问,了解或第二猜测数据库的业务逻辑。

There was a post regarding useful SQL tricks. Here I was going to mention the SQL Server Profiler tool, as it has helped me write less SQL. I would write SQL that would interrogate, understand or second guess the databases business logic.

Profiler是非常有用的,尤其是在应用code具有嵌入式SQL和你想看看它在做什么,在最短的时间内。 (你也可能不知道code版本在应用程序的环境中使用它的源,甚至更糟糕,那里是没有源$ C ​​$ C可用的!)。

Profiler is very useful, especially where application code has embedded SQL and you want to work out what it's doing, in the shortest time possible. (Also you may not know which source code version is used in the application's enviroment, or even worse, where there is no source code available!).

我在想,如果分析器有一个API,我可以钩到?

当我们想快速检查哪些SQL被调用时,系统内,通过设置环境变量/标志(PROFILER_ON = TRUE,例如)这将是非常有用的。然后系统可以揭开序幕SQL事件探查器,设置各种跟踪属性然后写了日志或表 - 这可能是由支持团队进行查看。

This would be very useful when we want to quickly check what SQL is called, within the system, by setting an environment variable/flag (PROFILER_ON=TRUE, for example). Then the system can kick off SQL profiler, setting various trace properties then writing out to a log or table - which could be viewed by the support team.

我想编写一个组件切换探查并监控生产环境(在安静的时候),所以不能真正改变codeBase类(包括应用程序code和SQL存储的特效)。

I want to write a component to switch profiler on and monitor the production environment (at quiet times) so can't really alter the codebase (both app code and SQL stored procs).

推荐答案

您可以利用的 Microsoft.SqlServer.Management.Trace 命名空间物体;它们提供针对SQL事件探查器提供同样功能的API。这是对脚本自己的SQL对数据库的替代品。然而,就像SQL事件探查器,这些对象在幕后做的是执行SQL跟踪存储的特效(或变体)创建,运行和管理的痕迹。

You can utilize the Microsoft.SqlServer.Management.Trace namespace objects; they provide an API against the same functionality that SQL Profiler provides. This is an alternative against scripting your own sql against the database. However, just like SQL Profiler, what these objects do under the covers is to execute the SQL Trace stored procs (or variations thereof) to create, run and manage the traces.

如果您使用1探查实例配置文件的另一(或从跟踪使用一个分析器通过删除个人资料本身的NOT LIKE'SQL事件探查器......'过滤标准(我认为这是一个应用程序的名称过滤器),那么你会看到它到底是什么,分析器正在做的是一样的你会做什么在SQL或什么SMO对象将从API做的。

If you use 1 profiler instance to profile another (or use a profiler to profile itself by removing the "NOT LIKE 'SQL Profiler...'" filter criteria from the trace (I think it's an Application Name filter) then you'll see exactly what it is that profiler is doing is the same as what you would do in SQL or what the SMO objects will do from an API.

这篇关于是否有可能自动SQL Server 2008中探查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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