Simple handling of SQL Server Stored Procedures exceptions

Source: Internet
Author: User

First, paste a self-written stored procedure for adding logs:

Alter procedure [DBO]. [writeblog] (@ in_id varchar (10), @ in_event varchar (100), @ out_parameter varchar (10) Output) as/** log writing stored procedure @ in_id user ID @ in_event Operation Event @ in_datetime operation time @ out_parameter return value 0 operation successful 1 Write failed */declare @ in_datetime datetime; set @ in_datetime = getdate (); begin tryinsert into blog values (@ in_id, @ in_event, @ in_datetime); Set @ out_parameter = '0 '; end trybegin catchset @ out_parameter = @ error; end catchreturn

Note:

The function of a stored procedure is to write its log information based on each operation on the database.

Exception Handling is critical, especially when a function or stored procedure returns a function or process. If you can include exception handling in the return value, in this way, you will know the exceptions when calling this process or function, so that you can debug them step by step.

The Stored Procedure also contains try catch statements, which are written in the above example.

For exception details, refer to the blog:

Http://www.cnblogs.com/sshoub/archive/2011/08/12/2136267.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.