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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trapping SQL error 547

Author  Topic 

Maracatu
Starting Member

13 Posts

Posted - 2003-12-10 : 06:44:58
Hi,
I want to be able to trap SQL error 547 in a sproc that performs a delete and return a non zero return value to the calling application without raising an exception in the calling application - instead the calling app will check the return value and output its own user friendly error if it detects the non zero value. Does anyone know if its possible to 'cancel'/suppress a SQL error?

Here is a section from my code :
DELETE FROM users
WHERE userId = @deleteUserId
AND siteId = @siteId
SELECT @sqlError = @@ERROR , @rowCount = @@ROWCOUNT
IF @sqlError=547
BEGIN
SET @sqlError=0
SET @mdrError=1037
SET @errorParam = 'user'
RETURN @mdrError
END

Thanks,
Mara

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2003-12-10 : 08:18:43
You cannot supress a SQL error. You have to write your application to handle it gracefully. For example, if you are using ADO, you could use "On Error Resume Next" and go through the Errors collection and handle the errors. Some info at: http://vyaskn.tripod.com/programming_faq.htm#q11

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -