try/catch select error

Hello experts,

I'm hoping someone can tell me what I'm doing wrong. I've got some procedures wrapped in transactions so that I can rollback and display a meaningful error if something goes wrong, but I'm not able to display the error in my classic ASP page.

Here's the code on the ASP page:

            rst.open "exec dbo.Test1 4, 2", conn
            response.write rst("returnme")
            rst.close

            rst.open "exec dbo.Test2 4, 2", conn
            response.write rst("returnme")
            rst.close

Here are the procs:

CREATE PROCEDURE [dbo].[Test1] ( @num1 int, @num2 int)
                       
AS

    Declare @resultbit bit, @divresult int

BEGIN TRY
BEGIN TRANSACTION

set @divresult = (@num1 / @num2)

COMMIT TRANSACTION
set @resultbit=1
END TRY

BEGIN CATCH
      ROLLBACK TRANSACTION
      set @resultbit=0
END CATCH

select @resultbit as returnme


CREATE PROCEDURE [dbo].[Test2] ( @num1 int, @num2 int)
                       
AS

    Declare @resultbit bit, @divresult int

BEGIN TRY
BEGIN TRANSACTION

UPDATE myTable SET recnum = @num1 WHERE recnum = @num2

COMMIT TRANSACTION
set @resultbit=1
END TRY

BEGIN CATCH
      ROLLBACK TRANSACTION
      set @resultbit=0
END CATCH

select @resultbit as returnme

When I run either proc directly against the database in SQL Management Server, I get a result of 1 for returnme, but what the ASP page displays is:

True

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal.


So why does the first function return a value and the second one not? They're identical except that the second function is updating a table.
            
Thank you!
EffinGoodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sybeCommented:
That is not how you call a stored procedure. Use a ADODB Command object. Sample code:

Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConnectioObject
oCmd.CommandText = "sp_stored_procedure_name"
oCmd.CommandType = 4

' parameters
oCmd.Parameters.Append oCmd.CreateParameter("@performance_id", 3, 1, 4, iPerformanceId)

' return recordset from stored procedure
Set oRS = Server.CreateObject("ADODB.Recordset")
oRS.CursorLocation = 3            'adUseClient
oRS.CursorType = 3                  'adOpenStatic
oRS.LockType = 4
Set oRS.ActiveConnection = Nothing
oRS.Open oCmd
Set oCmd = Nothing
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
above is good recommendation, and you should apply this.

but the underlying issue is likely somthing else.
please try to add this line (to both stored procedures) as first line of the code (after AS)

SET NOCOUNT ON

apart from that, if the only output is a single value, I would recommend you use OUTPUT parameters instead, this will also avoid the issue.
see this support note:
http://support.microsoft.com/kb/194792
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EffinGoodAuthor Commented:
Adding SET NOCOUNT ON resolved the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.