C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Errors in Sql Server 2005


Posted Date: 26 May 2008    Resource Type: Articles    Category: Databases

Posted By: Kapil Dhawan       Member Level: Gold
Rating:     Points: 10



Hi All,

Here i am writing some words on errors
i hope this will help someone.

All of the system and user-defined error messages in an instance of the Database Engine are contained in the sys.messages

The RAISERROR statement can be used to return user-defined errors to an application.

To Implement error handling for Transact-SQL we can use Try and Catch , same as we do in our C# application

Syntax :

BEGIN TRY
Sql statement goes here
END TRY
BEGIN CATCH
Sql statement goes here
END CATCH


• Try-Catch handles all exceptions with severity greater than 10 that do not terminate the database connection
• A Catch block must be there after Try Block
• If we will write anything between END TRY and BAGIN CATCH, it will surely raise an error.
• GoTo statements cannot be used to enter a TRY or Catch Block.
• We can not use Try –Catch between user defined function.


How to Retrieve Error:

ERROR_NUMBER(): return error number
ERROR_SEVERITY(): return the severity
ERROR_STATE(): return error state number
ERROR_PROCEDURE: return sp/trigger name
ERROR_LINE():return the line number
ERROR_MESSAGE():return the complete text of the error message.

BEGIN TRY
SELECT 1/0;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH
Run this script and see the detail of all above


Severity Level:

0-9 : return status info or report errors that are not severe. Database engine does not raise errors with severities 0 to 9.
10 : return status info or report errors that are not severe. For compatibility database engine converts severity 10 to 0 before returning the error info to the application.


please make me correct
if u find me wrong somewhere





Responses

Author: http://venkattechnicalblog.blogspot.com/    28 May 2008Member Level: Diamond   Points : 2
Please follow posting guidelines before submitting an article.

Regards,
Venkatesan Prabu . J


Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Author: John Fernandez    08 Jun 2008Member Level: Gold   Points : 1
Very well written Article.Thanks for sharing this information.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Sql Server Reporting Services (SSRS)
Previous Resource: Views in Sql Server 2005
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use