Raise custom errors from stored procedure, DOT NET Programming

Assignment Help:

How can you raise custom errors from stored procedure?

The RAISERROR statements are  used to produce an ad hoc error message or to retrieve acustom message which is stored in the sysmessages table. You can use this statement with the error handling code presented in the previous part to implement custom error messages in your applications. The syntax of the statement is shown below.

RAISERROR ({msg_id |msg_str }{,severity ,state }

[ ,argument [ ,,...n ] ] ))

[ WITH option [ ,,...n ] ]

The description of the components of the statement is as shown below:

msg_id :-This ID is used for an error message,that is stored in the error column in the sysmessages.

msg_str :-This shows a custom message that is not contained in sysmessages.

severity :- The severity level is associated with the error. The valid values are at 0-25.The Severity levels 0-18 can be used by any user, but 19-25 are only available to those members of the fixed-server role sysadmin. When the levels 19-25 are used, then the WITH LOG option is required.

The state A value that shows the invocation state of the error. The valid values are 0-127. That  value is not used by the SQL Server.

Argument, . . .

It is used by One or more variables that are used to customize the message. For e.g., you could pass the current process ID (@@SPID) so it could be displayed in the message.

WITH option, . . .

The three values that are used with this optional argument are described here.

LOG - It Forces the error to log in the SQL Server error log and the NT application log.

NOWAIT - This Sends the message immediately to the client.

SETERROR - This Sets @@ERROR to the unique ID for the message or 50,000.

The number of options available for the statement made it seem complicated, but it is actually simple to use. The following shows how to create an ad hoc message with the severity of 10 and a state of 1.

RAISERROR ('An error occurred during updating the NonFatal table',10,1)

--Results--

An error definitely occurred on updating the NonFatal table.The statement does not have to be used in the conjunction with any other code, but for our purposes it will be used with the error handling code presented earlier. The shown below alters the ps_NonFatal_INSERT procedure to use RAISERROR.

USE tempdb go

ALTER PROCEDURE ps_NonFatal_INSERT

@Column2 int =NULL AS

DECLARE @ErrorMsgID int

INSERT NonFatal VALUES (@Column2) SET @ErrorMsgID =@@ERROR

IF @ErrorMsgID <>0

BEGIN

RAISERROR ('An error occured updating the NonFatal table',10,1) END


Related Discussions:- Raise custom errors from stored procedure

Explain toolstrip drop-down button and split button, What is the difference...

What is the difference among a toolstrip drop-down button and a toolstrip split button? The difference among a toolstrip drop-down button and a toolstrip split button is that a

I am seeking to get a logo design for a business, I am seeking to get a log...

I am seeking to get a logo design for a business. Skills required: .NET, HTML, Graphic Design, PHP, Website Design

Develop nesting software with unit costing, Develop Nesting software with u...

Develop Nesting software with unit costing for gasket manufacturing Project Description: Our current gasket costing software is old and antiquated and has limited use interna

Function points, What are function points? The FPA is breaking huge sys...

What are function points? The FPA is breaking huge systems into smaller pieces and analyzing them. The Software application is a combination of set of elementary processes. The

Difference b/w msml and .net framework xml classes, What is the main differ...

What is the main difference b/w MSML and .NET Framework XML classes? The MSXML supports XML DOM and SAX parsers while the .NET framework XML classes support XML DOM and XML rea

Explain different types of xml application programming, Explain different t...

Explain different types of XML Application Programming Interface (API). The following are two main parts of XML parsers: Tree-based API - Compiles an XML document into a tre

Finding the frequencies - c# program, Finding the frequencies - C# Program:...

Finding the frequencies - C# Program: Please let me know how to find Frequencies in C#.

What is dbms, What is DBMS? It is a collection of programs that enables...

What is DBMS? It is a collection of programs that enables user to make and maintain a database. In other words it is general-purpose software that gives the users with the proc

Briefly explain how server form post-back works, Briefly explain how server...

Briefly explain how server form post-back works ?  Post Back: The process in which a Web page sends data back to the similar page on the server. View State : View State i

To know a state of a thread, How can we know a state of a thread? The "...

How can we know a state of a thread? The "ThreadState" property is used to get complete detail of a thread. The Thread can have one or a combination of status.System.Threading.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd