Page 1 of 1
EStackOverflow in TMSSQLMonitor
Posted: Thu 15 Sep 2016 15:59
by Eden0928
I want write monitor log when exec SQL in TMSSQLMonitor. My code below:
Code: Select all
procedure TDM.MSSQLMonitor1SQL(Sender: TObject; Text: string;
Flag: TDATraceFlag);
begin
MSQuery1.SQL.Text := 'INSERT INTO LOG_TABLE(MSG) VALUES(Text)';
MSQuery1.ExecSQL;
end;
But, I get the EStackOverflow: Stack overflow.
I don't know why?
Re: EStackOverflow in TMSSQLMonitor
Posted: Fri 16 Sep 2016 10:02
by azyk
The 'Stack overflow' error occurs due to a recursive call of the OnSQL event. This is because the ExecSQL method is called in the event handler, that leads to repeated call of the event and looping as a result. To avoid this error, you shouldn't call ExecSQL in the OnSQL event.
Re: EStackOverflow in TMSSQLMonitor
Posted: Fri 16 Sep 2016 10:33
by Eden0928
I need write log in my database.
Should I how to?
Thanks your reply!
Re: EStackOverflow in TMSSQLMonitor
Posted: Wed 21 Sep 2016 12:41
by azyk
Try to declare a global variable, whose value would allow to detect the SQL query, that called the OnSQL event: the application query or the logging query. For example:
Code: Select all
var
InLogging: boolean = False;
implementation
{$R *.dfm}
...
procedure TMainForm.MSSQLMonitor1SQL(Sender: TObject; Text: string;
Flag: TDATraceFlag);
begin
if not InLogging then begin
InLogging := True;
try
MSQuery2.SQL.Text := ...;
MSQuery2.ExecSQL;
finally
InLogging := False;
end;
end;
end;