如何监视通过 ADO 连接发送的 SQL 命令? [英] How can I monitor the SQL commands send over my ADO connection?
问题描述
我需要拦截在 ADO 连接组件和数据库服务器之间传递的所有 SQL 命令.类似于 dbExpress 的 TSQLmonitor ,但适用于 ADO .
i need intercept all the SQL commands that pass between an ADO connection component and a database server. something like the TSQLmonitor of dbExpress, but for ADO .
有人知道实现此功能的任何第三方组件吗?
Anybody know any third-party component that implements this functionality?
更新
我想做的是在不使用外部工具的情况下以编程方式(通过代码)从我的应用程序监视 SQL 语句.适用于任何数据库引擎.
I want to do is to monitor the SQL statements programmatically (by code) from my application without using an external tool. for any database engine.
推荐答案
我找到了解决方案,使用事件 TAdoConnection.OnWillExecute(发生在数据库服务器表示接受命令执行之后.)
I found a solution, use the event TAdoConnection.OnWillExecute (Wich occurs after a database server signals acceptance of a command execution. )
更多信息此处
procedure TDataModuleProd.ADOConnection1WillExecute(
Connection: TADOConnection; var CommandText: WideString;
var CursorType: TCursorType; var LockType: TADOLockType;
var CommandType: TCommandType; var ExecuteOptions: TExecuteOptions;
var EventStatus: TEventStatus; const Command: _Command;
const Recordset: _Recordset);
begin
AddLog(CommandText);
end;
我在我的博客上写了一篇小文章,供想要了解更多信息的人使用.
I wrote a small article on my blog, for those who want more information.
http://theroadtodelphi.wordpress.com/2010/02/21/build-your-own-profiler-using-ado/
这篇关于如何监视通过 ADO 连接发送的 SQL 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!