Getting Database Error Number

G

Guest

H
Does anyone know how to pass back the specific database error number from a SQL Server stored procedure, or else how the exception can beused to get this - I want to detect error 547 (foreign key violation) and display a more user friendly error message to the user but when the codes goes into the catch, all I can get from the exception is the full verbose error message ("DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_tblJob_tblClient'. The conflict occurred in database 'NIIR', table 'tblJob', column 'ClientID'
The statement has been terminated."

Many thank
Siobhan
 
W

William Ryan eMVP

Siobhan:

You can use InfoMessage to trap errors with a severity < 10
http://www.knowdotnet.com/articles/connections.html . I believe the Message
property of the sqlException's Errors Collection will give you the info your
need for exceptions with higher severity number).

HTH,

Bill
Siobhan said:
Hi
Does anyone know how to pass back the specific database error number from
a SQL Server stored procedure, or else how the exception can beused to get
this - I want to detect error 547 (foreign key violation) and display a more
user friendly error message to the user but when the codes goes into the
catch, all I can get from the exception is the full verbose error message
("DELETE statement conflicted with COLUMN REFERENCE constraint
'FK_tblJob_tblClient'. The conflict occurred in database 'NIIR', table
'tblJob', column 'ClientID'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top