Reputation: 6979
TADOConnection does not want to throw an exception when exception occurs after some result set has been returned. For example:
ADOConnection1.Execute('SET NOCOUNT ON; SELECT 0; THROW 50000, ''Custom error'', 1;');
The above code won't throw because there is a result set caused by SELECT 0;
How to force TADOConnection to throw an exception in such case? I can't avoid having a result set returned. Things I've tried:
OnInfoMessage
event, but it never gets fired.I've found an article that targets this issue, but it concerns .NET:
The Curious Case of Undetected SQL Exceptions
Upvotes: 1
Views: 248
Reputation: 12014
I was able to get the Custom Error
to show, using a TADOQuery
like this:
var
t : integer;
begin
ADOQuery1.SQL.Text := 'SET NOCOUNT ON; SELECT 0; THROW 50000, ''Custom error'', 1;';
ADOQuery1.Open;
t := 0;
ADOQuery1.NextRecordset(t); // exception thrown here
end;
Upvotes: 2