How can I control the sending of SQL commands through my ADO connection?

I need to intercept all the SQL commands that pass between the ADO connection component and the database server. something like TSQLmonitor dbExpress, but for ADO.

Does anyone know of any third-party component that implements this functionality?

UPDATE

I want to do to track SQL statements programmatically (by code) from my application without using an external tool. for any database engine.

+2
source share
4 answers

I found a solution using the TAdoConnection.OnWillExecute event (This happens after the database server signals acceptance of the command.)

More here

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 short article on my blog for those who want more information.

http://theroadtodelphi.wordpress.com/2010/02/21/build-your-own-profiler-using-ado/

+8
source

If your database is MS-SQL, you can track SQL traffic using the SQL Profiler tool. There are quite a few configuration guides, including this one .

+6
source

Since you are requesting some kind of database engine, I believe that the only reliable approach is the application for your application to register SQL before executing it. There are several ways to do this, from creating child objects from existing TAdoxxxx to creating simple functions that you need to remember every time you want to check something. Regarding logging, one of the preferred methods is to use outputdebugstring to send it to the debug console. When Delphi is running, it will be displayed in the message box. There is a standalone executable DebugView that can be used on remote systems.

If you just want to access SQL during debugging (so you can test and configure an external application), and using the tAdoQuery component, you can use a debugging evaluator to save this to a file. Just set a breakpoint right before opening, then at the breakpoint, start the debug analyzer and enter the name of your query component, and then: .sql.savetofile('c:\sqlfilename.sql') and then press return, it will save all existing SQL in the specified file, It can be a lifesaver if your SQL is generated or is too large to view using the debug inspector.

0
source

I published how to use Windbg as an SQL profiler to get all sql calls from an application.

This can be easily changed to use it for any database. With this, I am trying to demonstrate how we could trace something from the bottom of the stack.

0
source

All Articles