🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1383

Handling SQL Server Error with ADO Connection

#1383
From: Bruno GAUTIER
Date: Fri, 30 Jul 2004 14:01
57 lines
2119 bytes
Hello,

I use a stored procedure on SQL Server like that :

---------------------------------
CREATE PROCEDURE Test @v_Id1 int, @v_Libelle1 varchar(20), @v_Id2 int,
@v_Libelle2 varchar(20)
AS

declare @v_res = 0

INSERT INTO TABLE1 (TAB_ID; TAB_LIBELLE) VALUES (@v_Id1, @v_Libelle1)

if @@ERROR <> 0
  @v_res = 1

if @v_res=0
begin
  INSERT INTO TABLE2 (TAC_ID; TAC_LIBELLE) VALUES (@v_Id2, @v_Libelle2)
  if @@ERROR <> 0
  @v_res = 2
end
if (res = 0)
begin
/*
   ...
*/
end

return (@v_res)
---------------------------------

Sometimes, this procedure raises an error on one of the insert call. I would
like to read the @v_res value in my C++ Builder program.

I try the following code but it doesn't work. If the execProc fails, the
value is always 0.

try
{
   maprocStock->ExecProc();
    res =(int)maprocStock->Parameters-> ParamValues["@v_codeRetour"];
}
catch(Exception &newDBException)
{
     // @v_codeRetour is a 'pdReturnValue' parameter pdReturnValue
     res =(int)maprocStock->Parameters-> ParamValues["@v_codeRetour"];
 }

First question : How can I read the good value ?
Second question : How can I read the exception code ? I only get the
message.

Thanks a lot


Bruno
Technical Details
Message-ID: <410a54af$0$24057$626a14ce@news.free.fr>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!feeder2-1.proxad.net!news2-e.free.fr!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,a32920895693e60f,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!feeder2-1.proxad.net!news2-e.free.fr!not-for-mail
From: "Bruno GAUTIER" <bruno.gautier_NOSPAM@basystemes.fr>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Handling SQL Server Error with ADO Connection
Date: Fri, 30 Jul 2004 16:01:56 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Lines: 59
Message-ID: <410a54af$0$24057$626a14ce@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 30 Jul 2004 16:01:19 MEST
NNTP-Posting-Host: 217.167.0.1
X-Trace: 1091196079 news2-e.free.fr 24057 217.167.0.1:14697
X-Complaints-To: abuse@proxad.net