Use SQLServer to process data layer errors

Source: Internet
Author: User
Developers are trying to properly handle accidents, so that users do not have to worry about system error messages like tianshu. For this reason, exception handling is a standard part of every. NET application. The Try/catch Block allows you to capture exceptions and control application execution from this point. Many errors may occur when interacting with databases,

Developers are trying to properly handle accidents, so that users do not have to worry about system error messages like tianshu. For this reason, exception handling is a standard part of every. NET application. The Try/catch Block allows you to capture exceptions and control application execution from this point. Many errors may occur when interacting with the database,

Developers are striving to properlyProcessingBy default, users do not have to worry about the tianshu system.ErrorInformation. For this reason, an exception occurs.ProcessingIs a standard part of every. NET application. The Try/catch Block allows you to capture exceptions and control application execution from this point. AndDataThe library performs many interactive operations.ErrorBut many developers do not know howProcessingDataLibrary LayerError. This article will explore how to use SQLServer and T-SQLProcessingYouDataLibrary codeError.

ProcessingIn T-SQLError

SQL conversation of SQLServer allows you to easilyProcessingNon-fatal events that may occur in stored processes and functionsErrorBut not allErrorEasy to useProcessing. In fact, both fatal and non-fatalErrorThere are many. What is fatal, what is non-fatal, there is no complete documentation on this, but your application code can always use try/catch BlockProcessingFatalDataLibraryError. For all otherErrorYou can use the following technologies.

Transactions

You shouldDataUse transactions in the library code to ensure that all changes are completed when everything is okay. SQL Server online help describes a transaction as a logical unit of a task. It consists of a series of statements (select, insert, update, or delete. If noError, All changes to the transaction will becomeDataThe permanent part of the database. IfError, NoDataLibrary.

A transaction is included between the begin transaction and end transaction statements. The rollback transaction statement can cancel all changes without any changes. You can use the commit transaction statement to make permanent changes. Now let's focus on howProcessingIn T-SQLError.

@ Error

@ Error function enables you to implement T-SQLErrorProcessing. It returnsErrorCode. If noErrorIf this happens, "0" is returned ". @ Error the function must be called immediately after a statement because it is cleared after each T-SQL statement.

12 3 4 next page

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.