MSScript not raising exception

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
JensFudge
Posts: 35
Joined: Mon 12 Jan 2009 08:37

MSScript not raising exception

Post by JensFudge » Wed 26 Oct 2011 19:13

Hi

I am using an MSScript component, that I fill the SQL in dynamically.

Sometimes the SQL that gets filled in is with errors, like incorrect syntax near bla bla, or field not found or whatnots... BUT

MSScript.execute does NOT raise an exception, in stead it shows an error message to the user, with looks like a showmessage.

This is useless, as I cannot handle the error the correct way.

Am I correct in assuming that you showmessage and not raise an exception?

Best regards

Jens Fudge

AndreyZ

Post by AndreyZ » Thu 27 Oct 2011 12:43

Hello,

Exceptions that can be raised during TMSScript execution are handled by the Application.HandleException method by default. To change such behaviour, you should use TMSScript.OnError event handler in the following way:

Code: Select all

procedure TMainForm.BitBtnClick(Sender: TObject); 
begin
  try
    MSScript.SQL.Text := 'CREAET TABLE TEST(ID INT)';
    MSScript.Execute;
  except
    ShowMessage('error');
  end;
end;

procedure TMainForm.MSScriptError(Sender: TObject; E: Exception; SQL: String;
  var Action: TErrorAction);
begin
  Action := eaFail;
end;
In this case you will be able to handle exceptions on your own. For more information, please read the SDAC documentation.

Post Reply