Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
SQL SERVER AND ERROR MESSAGES
I want to display my own error message when something goes wrong in executing the below procedure rather than displaying the sqlserver error message.
Suppose in the below procedure during updation if we set value of attribute, 'userid' which already exists in the database, an error willbe raised by sqlserver as 'userid' is primary key and duplicates are not allowed. Eventhough I incorporated a sql, 'select' statement whch intimates about error and rollback the transaction , sqlserver error message is displayed rather than the 'select' statement result which intimates me about the error encounterd. Can anyone of you suggest how to override the sqlserver error message and displaying my own error message and how could we get the sqlserver raised error description.
CREATE procedure admin_modify@olduserid
= count(*) from admin where userid = @olduserid
select 'failure' as result,'Admin ' + @olduserid
+ 'Not Found' as description
set userid = @newuserid
,password = @newpassword
where userid = @olduserid
and password = @oldpassword
select 'failure' as result,'Error Encountered While Modifying Admin ' + @olduserid
+ 'Details' as description
select 'success' as result,'' as description
0 · ·