EStackOverflow in TMSSQLMonitor

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Eden0928
Posts: 47
Joined: Sun 22 Apr 2012 14:08

EStackOverflow in TMSSQLMonitor

Post by Eden0928 » Thu 15 Sep 2016 15:59

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?

azyk
Devart Team
Posts: 1058
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: EStackOverflow in TMSSQLMonitor

Post by azyk » Fri 16 Sep 2016 10:02

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.

Eden0928
Posts: 47
Joined: Sun 22 Apr 2012 14:08

Re: EStackOverflow in TMSSQLMonitor

Post by Eden0928 » Fri 16 Sep 2016 10:33

I need write log in my database.

Should I how to?

Thanks your reply!

azyk
Devart Team
Posts: 1058
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: EStackOverflow in TMSSQLMonitor

Post by azyk » Wed 21 Sep 2016 12:41

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;

Post Reply