How to use TMSScript.OnError
Posted: Mon  05 Dec 2016 14:46
				
				I use TMSScript to run scripts in a loop.
As I upgrade my applciation to version N+1 there is a number of scripts like
010.sql
011.sql
...
025.sql
that are run sequentially with TMSScript.Execute.
Up to now I used OnError to handle errors like this
Now I would like to distinguish between exceptions that are due to a real Sql Server issue (like violation of FK. truncation errors, ...) and other exceptions (system out of resources or any other issue that can make a query fail).
Please suggest me how to do.
Should I filter by Exception type or do something in OnError?
Thanks
			As I upgrade my applciation to version N+1 there is a number of scripts like
010.sql
011.sql
...
025.sql
that are run sequentially with TMSScript.Execute.
Up to now I used OnError to handle errors like this
Code: Select all
scrUpgrader: TMSScript;
[...]
// this is how the OnError eventhandler is setup (one line of code)
procedure TfrmUpgrader.scrUpgraderError(Sender: TObject; E: Exception;
  SQL: string; var Action: TErrorAction);
begin
  Action := eaFail;
end;
// this is how i execute the script in a loop (i exclude the loop code):
        try
          scrUpgrader.SQL.Clear;
          scrUpgrader.SQL.LoadFromFile(ScriptName);
          scrUpgrader.Execute;
        except
          On E:Exception do
          begin
            Result := False;
            
            msg := Format('Error in script %s'+#13#10,[i]);
            memLog.Lines.Append(msg);
        end;Please suggest me how to do.
Should I filter by Exception type or do something in OnError?
Thanks