Retrieve output parameters from failed stored procedure

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Retrieve output parameters from failed stored procedure

    Is it possible to retrieve output parameters (adParamOutput) from a
    stored procedure (asp/sql server) even when the procedurte fails - or
    is it only possible to retrieve return values (adParamReturn). I can
    retrieve output values when the procedure succeeds but not when it
    fails. If it can be done i will go back and look at my code.

    Thanks in advance

    stuart
    stuart Guest

  2. Similar Questions and Discussions

    1. Optional Parameters ASP to SQL stored procedure
      Hi there, Can someone help, this is driving me crazy I have written a stored procedure in sql with input, output and return parameters. This...
    2. Stored Procedure Output using ASP
      Hi, I've written an sproc which inserts customer data into a SQL table, then stores a variable as the unique id of the row (@orderid) ... then...
    3. Stored Procedure Parameters (text)
      I have a stored procedure that takes parameter @description with datatype set to text. In my ASP I have the following: ..Parameters.Append...
    4. Need more help on how to pass parameters from stored procedure into trigger
      Thanks oj for responding to my query. But since I am a novice I was able to decipher the statements but was not able to determine where should all...
    5. How to Pass stored procedure parameters inside trigger
      I have an Update trigger defined on PITRY table. This trigger in turn inserts old records from PITRY table into PITRYAudit and inserts the related...
  3. #2

    Default Re: Retrieve output parameters from failed stored procedure

    You will need some kind of error handling in your sproc. In your error
    handling code, set the output parameter.

    Cheers
    Ken

    "stuart" <stuart.cochrane@kellogg.com> wrote in message
    news:7ce2ca9e.0402120249.4de69562@posting.google.c om...
    : Is it possible to retrieve output parameters (adParamOutput) from a
    : stored procedure (asp/sql server) even when the procedurte fails - or
    : is it only possible to retrieve return values (adParamReturn). I can
    : retrieve output values when the procedure succeeds but not when it
    : fails. If it can be done i will go back and look at my code.
    :
    : Thanks in advance
    :
    : stuart


    Ken Schaefer Guest

  4. #3

    Default Re: Retrieve output parameters from failed stored procedure

    stuart wrote:
    > Is it possible to retrieve output parameters (adParamOutput) from a
    > stored procedure (asp/sql server) even when the procedurte fails - or
    > is it only possible to retrieve return values (adParamReturn). I can
    > retrieve output values when the procedure succeeds but not when it
    > fails. If it can be done i will go back and look at my code.
    >
    > Thanks in advance
    >
    > stuart
    Can you provide a short repro script so we can see what you're talking
    about? Just write a quicky sproc using one of the pubs or Northwind tables
    and show the ado code used to reproduce your issue.

    Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  5. #4

    Default Re: Retrieve output parameters from failed stored procedure

    Hi Bob,

    Below is a sample of asp and tsql code:

    Thanks for any help or advice - For some reason if the insert succeeds i
    can retrieve the output parameters, but if the insert fails(i.e. if a
    primiary key is violated) the output parameters are empty.

    Stuart


    //asp code

    on error resume next

    set objCmd = server.createobject("ADODB.command")
    objCmd.CommandText = "ps_ProcessLineIns"
    objCmd.CommandType = adCmdStoredProc
    set objCmd.Activeconnection = objConn

    set objParam = objCmd.CreateParameter("@i_pl_code", adVarChar,
    adParamInput, 10, pl_code)
    objCmd.parameters.Append objParam
    set objParam = objCmd.CreateParameter("@i_pl_name", adVarChar,
    adParamInput, 50, pl_name)
    objCmd.parameters.Append objParam
    objCmd.parameters.Append objParam
    set objParam = objCmd.CreateParameter("@o_message_id", adVarChar,
    adParamOutput)
    objCmd.parameters.Append objParam
    set objParam = objCmd.CreateParameter("@o_message_text", adInteger,
    adParamOutput)
    objCmd.parameters.Append objParam

    objcmd.Execute

    o_message_text = objCmd.Parameters("@o_message_id").value
    o_message_id = objCmd.Parameters("@o_message_text").value

    /////TSQL code


    CREATE procedure ps_ProcessLineIns (
    @i_pl_code varchar(10) , -- Process Line Code - In
    @i_pl_name varchar(50) , -- Process Line Name - In
    @i_pl_description varchar(50), -- Process Line description -In
    @o_message_id int output, -- Message ID - Out
    @o_message_text varchar(100) output -- Message Text - Out
    )
    as
    set nocount on
    --
    declare @ErrorSave INT
    set @ErrorSave = 0
    --
    Begin
    -- Insert Process Line after passing validation.
    insert into PROCESS_LINES

    (PL_CODE,PL_NAME,PL_DESCRIPTION,F_PA_ID,F_LOV_PROC ESS_LINE_TYPE_ID,STATU
    S,
    CREATED_DATETIME,CREATED_BY)
    values

    (@i_pl_code,@i_pl_name,@i_pl_description,@i_pa_id, @i_pl_line_type_id,@i_
    pl_status,getdate(),@i_user_id);

    -- Trap Error Code
    Set @ErrorSave = @@error
    if @ErrorSave <> 0 goto errorhandler
    --
    Set @o_message_id = 0
    Set @o_message_text = 'Insert Success'
    --
    errorhandler:
    Set @o_message_id = @ErrorSave
    Set @o_message_text = 'Insert Failed'
    End
    GO






    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Stuart Cochrane Guest

  6. #5

    Default Re: Retrieve output parameters from failed stored procedure

    Does it work as expected when run in Query Analyzer? I.E. if you pass
    parameters that cause an error, are the ouput parameters correctly
    populated?

    --In QA:
    declare @i_pl_code varchar(10),@i_pl_name varchar(50),
    @i_pl_description varchar(50), @o_message_id int,
    @o_message_text varchar(100)

    --set the above variables to values that will cause an error in the sproc,
    then:
    exec ps_ProcessLineIns @i_pl_code,),@i_pl_name,@i_pl_description,
    @o_message_id output,@o_message_text output
    select @o_message_id [Output Message ID], ,@o_message_text [Output Message
    Text]


    See below for my initial comments. If my suggested changes do not help,
    could you supply a CREATE TABLE script for the PROCESS_LINES table? Relevant
    columns and primary key ...

    Bob Barrows

    Stuart Cochrane wrote:
    <snip>
    > set objCmd.Activeconnection = objConn
    >
    Add this line (I added the With block to enable the command to fit your line
    width):
    with objCmd
    ..parameters.Append .CreateParameter(@RETURN_VALUE, _
    adInteger, adParamReturnValue)
    end with
    > set objParam = objCmd.CreateParameter("@i_pl_code", adVarChar,
    > adParamInput, 10, pl_code)
    > objCmd.parameters.Append objParam
    > set objParam = objCmd.CreateParameter("@i_pl_name", adVarChar,
    > adParamInput, 50, pl_name)
    > objCmd.parameters.Append objParam
    > objCmd.parameters.Append objParam
    Why is this line repeated?
    > set objParam = objCmd.CreateParameter("@o_message_id", adVarChar,
    > adParamOutput)
    > objCmd.parameters.Append objParam
    > set objParam = objCmd.CreateParameter("@o_message_text", adInteger,
    > adParamOutput)
    > objCmd.parameters.Append objParam
    >
    > objcmd.Execute
    objcmd.Execute ,,adExecuteNoRecords



    Bob Barrows [MVP] Guest

  7. #6

    Default Re: Retrieve output parameters from failed stored procedure

    Hi Bob,

    Yes, if I run the code in Query Analyzer everything is okay and I
    receive the correct output parameters.

    Stuart

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Stuart Cochrane Guest

  8. #7

    Default Re: Retrieve output parameters from failed stored procedure

    Stuart Cochrane wrote:
    > Hi Bob,
    >
    > Yes, if I run the code in Query Analyzer everything is okay and I
    > receive the correct output parameters.
    >
    > Stuart
    >
    So what about the second part of my post ... ?

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139