Page 1 of 1

How to get query text from EMSError

Posted: Fri 28 Jun 2013 09:11
by Ludek
Hello,
I'm trying to protocol exceptions in my app and want to include the whole query text, when the error is EMSError.
I can do following

Code: Select all

e: EMSError;
begin
  if e.Component is TMSQuery then ... TMSQuery(e.Component).sql.text ...
works fine, if the query is placed on form, datamodule etc. But if the query is just ad-hoc, like

Code: Select all

  q: TMSQuery;
begin
  q := TMSQuery.Create;
  try
    ...
    q.execsql
  finally
    q.free;
  end;
the field EMSError.Component is empty.
I understand, that is has to be empty, as the component is already freed, when the global exception handler comes to action.

But - is there some way to extend the EMSError class to include the query text as a string attribute, so that also in such cases the global exception handler can get the text, even when the query is already destroyed?

Thanks for info,
Ludek.

Re: How to get query text from EMSError

Posted: Mon 01 Jul 2013 12:15
by AlexP
Hello,

For global error handling, you can use the onError event of the TMSConnection component. In this case, an event will occur just on error occurrence, and the component, in which the error occurs, will not be destroyed:

Code: Select all

procedure TForm1.MSConnection1Error(Sender: TObject; E: EDAError;
  var Fail: Boolean);
begin
  ShowMessage(TMSQuery(e.Component).SQL.Text);
end;

Re: How to get query text from EMSError

Posted: Thu 04 Jul 2013 13:56
by Ludek
Thank you for information!
Now do i have to find out, how can i pass this text to the global event handler... currently no idea :(

Re: How to get query text from EMSError

Posted: Thu 04 Jul 2013 14:07
by Ludek
Can I raise there my own exception (and access the original exception in the handler using innerexception), or is that not possible, i break so something in sdac?

Re: How to get query text from EMSError

Posted: Thu 04 Jul 2013 14:56
by AlexP
Hello,

You can generate your exception in this event - and this will not affect SDAC functioning

Re: How to get query text from EMSError

Posted: Fri 02 Aug 2013 12:56
by Ludek
Thank you!

Re: How to get query text from EMSError

Posted: Mon 05 Aug 2013 07:29
by AndreyZ
If any other questions come up, please contact us.