I need to execute a password reset on a Sybase ASE dataserver based on certain conditions:
if validations_here
begin
exec sp_password 'sso_passw', 'new_passw', @userid
end
sp_password
might raise some errors, e.g. 10316 - "New password supplied is the same as the previous password". Although I couldn't find any documentation, I think they shouldn't be fatal errors and it should be possible to emulate them with raiserror
.
Since it would be easier for the caller to handle it that way, I would like to get the error code and return it as part of a resultset, so I thought about SELECTing @@error. My code is as follows (I transcribed only those parts I think are relevant to the problem):
create procedure sp_desbloc_blanqueo_usr
@userid sysname,
@sso_pass varchar(20),
@new_pass varchar(20)
as
begin
declare @ret_code int
declare @ret_msg varchar(100)
declare @myerror int
select @ret_code = 0, @ret_msg = 'OK'
exec sp_password @sso_pass, @new_pass, @userid
set @myerror = @@error
if @myerror <> 0
begin
select @ret_code = @myerror, @ret_msg = 'Error occurred changing password'
-- It would be nice to have the actual error message as well
goto fin
end
fin:
select @ret_code as ret_code, @ret_msg as ret_msg
end
However, whenever I execute the stored procedure, I get 0 as ret_code
and OK as ret_msg
(even if parameters to sp_password
are wrong).
How can I "catch" the error code of sp_password
from my stored procedure?