Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exception - hot to get SQLServer Err. number

Posted on 2000-05-18
7
Medium Priority
?
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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