Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Customize SQL error message for VB.NET App use Expand / Collapse
Author
Message
Posted Friday, October 5, 2012 6:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, October 5, 2012 10:02 PM
Points: 6, Visits: 14
I am wondering if there is a way to overwrite or customize the system error thrown by SQL server. For example error message 521,instead of the default message you could customize or overwrite it with your own version of text.

What I wanted to achieve is to have my own error message displayed by a VB.NET App when SQL server throws an exception that there is a duplicate value in the table.
Post #1368969
Posted Friday, October 5, 2012 8:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:05 PM
Points: 13,327, Visits: 12,820
crux1187 (10/5/2012)
I am wondering if there is a way to overwrite or customize the system error thrown by SQL server. For example error message 521,instead of the default message you could customize or overwrite it with your own version of text.

What I wanted to achieve is to have my own error message displayed by a VB.NET App when SQL server throws an exception that there is a duplicate value in the table.


Of course there is. Use Try-Catch in your VB app. Do you have a data layer? That would be the best place to capture this. All you need to do it catch the error and throw your own exception with your custom message.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1369065
Posted Friday, October 5, 2012 10:06 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, October 5, 2012 10:02 PM
Points: 6, Visits: 14
Can you provide me with some link or any code if there is any?
Post #1369379
Posted Sunday, October 7, 2012 12:27 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, December 12, 2014 4:13 AM
Points: 112, Visits: 340
Hi,
In both SQL Server and VB.NET you have to use Try catch block.

What ever error you grab in SQL Server catch box just Raised it with RAISERROR syntax.

Now in VB.NET you can capture this and show or do what ever operation you want.
Post #1369555
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse