How to get query text from EMSError

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

How to get query text from EMSError

Post by Ludek » Fri 28 Jun 2013 09:11

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.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to get query text from EMSError

Post by AlexP » Mon 01 Jul 2013 12:15

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;

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Re: How to get query text from EMSError

Post by Ludek » Thu 04 Jul 2013 13:56

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 :(

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Re: How to get query text from EMSError

Post by Ludek » Thu 04 Jul 2013 14:07

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?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: How to get query text from EMSError

Post by AlexP » Thu 04 Jul 2013 14:56

Hello,

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

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Re: How to get query text from EMSError

Post by Ludek » Fri 02 Aug 2013 12:56

Thank you!

AndreyZ

Re: How to get query text from EMSError

Post by AndreyZ » Mon 05 Aug 2013 07:29

If any other questions come up, please contact us.

Post Reply