trapping a MS SQL raiserror with try...except ?


2004-12-07 07:04:45 AM
delphi115
Dear All
I am using a MS SQL insert trigger to trap an error condition , rollback
transaction and use :
---- insert trigger
...... other code here
if @EOMcount>0
begin
ROLLBACK TRANSACTION
RAISERROR ('Posting denied, Cannot post to closed period',1,1)
RETURN
end
--------------------
The trigger does its job correctly but my dephi code does not raise an
exception , how do I detect my own raiserror from dephi , the code below
does not execute the except block, although the trigger rolledback the
transaction.
datamodule1.database1.starttransaction;
try
datamodule1.q_temp.ExecSql;
ALLtransquery.ExecSql;
except
on E:exception do
begin
statusbar1.simpletext := 'Error changing batch no, contact
MIS';
showmessage ('Error changing batch no, contact MIS' + #10 +
#13 +
'BDE code 1 : ' + inttostr((E as
Edbengineerror).errors[0].errorcode) + #10 + #13 +
'BDE code 2 : ' + inttostr((E as
Edbengineerror).errors[1].errorcode) + #10 + #13 +
'message 1 : ' + (E as
Edbengineerror).errors[0].message + #10 + #13 +
'message 2 : ' + (E as
Edbengineerror).errors[1].message);
{Error Occured }
DataModule1.Database1.rollback;
exit;
end;
end;
datamodule1.database1.commit;
Dennis.