Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nic
Posting Yak Master
209 Posts |
Posted - 2001-09-17 : 14:10:55
|
| Hi,I'm building a web application and I'm trying to add some error trapping to my stored procedures. I'm a little confused on how to just return the RETURN value and not the error message (page can not be displayed). When I cause an error, the error trapping works correctly (the transaction is rolled back) but the web page still displays the database error. Is there any way to do something like "on error resume next" (VB). When I exec the sp from ISQL, the error message and return value is displayed. I only want the return value to be displayed. Here is a sample sp:CREATE PROCEDURE mc_modTest(@test_data varchar(10)='',@test2_data varchar(10)='')ASDECLARE @newkey intDECLARE @error_test intDECLARE @error_test2 intSET @error_test = 0SET @error_test2 = 0SET NOCOUNT ONSELECT @newkey = (SELECT ISNULL(MAX(test_key)+ 1,1) FROM tblTest)--start transactionBEGIN TRANINSERT INTO tblTest2 (test2_key,test2_data) VALUES (@newkey,@test2_data) -- check for errorsSET @error_test2 = @@ERRORINSERT INTO tblTest (test_key,test_data) VALUES (@newkey,@test_data) -- check for errorsSET @error_test = @@ERROR-- Test the error values.IF @error_test = 0 AND @error_test2 = 0BEGIN -- Success. Commit the transaction. COMMIT TRANENDELSEBEGIN -- An error occurred. Rollback the transaction. IF @error_test <> 0 BEGIN ROLLBACK TRAN RETURN(@error_test) END IF @error_test2 <> 0 BEGIN ROLLBACK TRAN RETURN(@error_test2) ENDENDSET NOCOUNT OFFGO Does my question make sense?Nic |
|
|
|
|
|