Option 1) using a collection of ADO connection errors.
try
....
....
....
ADOQuery1.Open;//Execute your sql statement
except
LastErrorIndex :=ADOConnection1.Errors.Count-1;
SourceError :=ADOConnection1.Errors.Item[LastErrorIndex].Source;
NumberError :=ADOConnection1.Errors.Item[LastErrorIndex].Number;
DescriptionError:=ADOConnection1.Errors.Item[LastErrorIndex].Description;
SQLStateError :=ADOConnection1.Errors.Item[LastErrorIndex].SQLState;
NativeError :=ADOConnection1.Errors.Item[LastErrorIndex].NativeError;
end;
Option 2) You can use the @@ error variable to get the latest error on the sql server.
select @@error
If an error occurs on the Sql server, all you can get is the error number using the global variable @@ ERROR. There is no global variable @@ ERROR_MESSAGE to get a description of the error. For a complete error message, you can query the master..sysmessages table using the error number:
SELECT Description FROM master..sysmessages WHERE error= @@ERROR AND msglangid=1033
but most of these messages have placeholders (for example,% s,% ld), you can also use this Stored procedure .
SQL Server - .
Bye.