是否可以自动化SQL Server 2008分析器? [英] Is it possible to automate SQL Server 2008 profiler?

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

问题描述

帖子关于有用的SQL技巧。在这里,我将提到 SQL Server Profiler 工具,因为它已经帮我写了更少的SQL。我将编写可以询问,理解或第二次猜测数据库业务逻辑的SQL。



Profiler非常有用,特别是当应用程序代码嵌入了SQL,它在做什么,在最短的时间内。 (也可能你不知道在应用程序的环境中使用哪个源代码版本,甚至更糟糕的是,没有可用的源代码。)



想知道分析器是否有一个API可以挂钩?



这将是非常有用的,当我们想快速检查什么SQL被称为,系统,通过设置环境变量/标志(例如PROFILER_ON = TRUE)。然后系统可以启动SQL分析器,设置各种跟踪属性,然后写出到日志或表 - 这可以由支持团队查看。



我想编写一个组件来切换分析器并监视生产环境(在安静的时间),所以不能真正改变代码库(应用代码和SQL存储


解决方案

您可以使用 Microsoft.SqlServer.Management.Trace 命名空间对象;它们提供的API与SQL Profiler提供的功能相同。这是一种替代方法,可以针对数据库编写您自己的sql。但是,就像SQL Profiler一样,这些对象在这些方面做的是执行SQL Trace存储过程(或其变体)来创建,运行和管理跟踪。



如果您使用1个分析器实例来配置另一个(或使用分析器通过从跟踪中删除不喜欢'SQL Profiler ...'过滤器条件来归档自己的配置文件)(我认为它是应用程序名称过滤器)看到它是什么,是什么,是什么,你会做什么在SQL或什么SMO对象将从一个API。


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

I was wondering if the profiler has an API I could hook into?

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.

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

解决方案

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.

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天全站免登陆