Solved

Exception - hot to get SQLServer Err. number

Posted on 2000-05-18
7
385 Views
Last Modified: 2010-04-04
I'm using D5 and ADO components to access SQL Server. Is there a way to retrieve SQL server error code, when exception is raised? For example: I use ADOQuery to execute stored procedure, and the procedure is missing, how can I catch this error?
0
Comment
Question by:pvs001d
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Author Comment

by:pvs001d
ID: 2824423
Adjusted points from 50 to 100
0
 
LVL 2

Expert Comment

by:IPCH
ID: 2824558
Can you send part of you code?
0
 
LVL 15

Accepted Solution

by:
simonet earned 100 total points
ID: 2925829
You should use the TADOStoredProc component.

After you call the EXecProc method, the parameter @RESPOST (or something like that... it's always the 1st parameter in the TADOStoredProc parameters list) will be filled with the result code of the execution.

Just read its value and you know what happened. The Online Books for SQL Server 7 lists all the error codes that can be returned.

Alex
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:simonet
ID: 2930573
Correction:

the parameter is called @RETURN_VALUE and every stored procedure automatically defines this parameter. Remember that you must set its direction as output in the TADOStoredProc's Parameter's editor.

Alex
0
 

Author Comment

by:pvs001d
ID: 3431312
Answer accepted
0
 

Expert Comment

by:radu_antohi
ID: 9204001
The paramater is called @RETURN_VALUE, but the parameter direction is not 'pdOutput', but 'pdReturnValue'.

Delphi Example:

var
  Ret: Integer;
begin
  ADOConnection1.Connected := True;

  ADOStoredProc1.Parameters.Clear;
  ADOStoredProc1.Parameters.CreateParameter('@RETURN_VALUE', ftInteger, pdReturnValue, 0, NULL);

  ADOStoredProc1.ExecProc;

  Ret := ADOStoredProc1.Parameters.ParamByName('@RETURN_VALUE').Value;

  ShowMessage(IntToStr(Ret));
end;
0
 

Expert Comment

by:radu_antohi
ID: 9204093
Another way to get the error id is from the exception raised with RAISERROR by the SQL Server.

try
 SP.ExecProc;
except
 on E: EOleException do
 begin
  if (ADOConnection.Errors.Count > 0) then
  begin
   NativeError := ADOConnection.Errors[0].NativeError;
   Description := ADOConnection.Errors[0].Description;
  end
 end;
end;

The best way for error handling is to use both methods (exceptions raised with RAISERROR and RETURN_VALUE), because there are exceptions that are not catched by tke OLEDb provider or by Delphi. I don't know where is the problem.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 96
Delphi selector screen 2 69
Correct Component for Shopping Cart. 2 95
Convert GUI app into console app for Win32 Env 5 78
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now