Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching check constraint errors from SQL in VB

Status
Not open for further replies.

bascy

Programmer
Mar 6, 2001
53
NL
Hello all,

I have a VB-application using a SQL-server database with various tables, triggers, stored procedures, etc.

I want to guard the integrity and consistency of the data with check-contraints and triggers on the tables. With triggers it is possible to raise a user-defined error, which i can catch in VB to display it in a user-friendly form. Is such a construction also possible with Constraints?

Is there anybody that can tell me how I can solve this problem.

thanks
B
 
Hi B,
I am using this method to generate user defined messages for check constraints.
1) Create a table error_msg with constraint no. and error message.
2) Whenever create any check constraint, insert the constraint no. and user defined message in the error_msg table.
3) Whenever you receive an error from the backend, you can search error_msg table for the required message.
If the constraint exist there show your message otherwise show the message which you got from the back-end.

Hope this will help you in right direction.
 
Sorry B, I forget to explain this also.
1) Whenever a check constraint fails SQL server returns message line having following text also,
... &quot;CHECK constraint <constraint name>&quot; ...
So you can easily find the constraint code from back-end error message and then follow as per above process.
 
Thanks for the rapid answer.

It is a good suggestion, even though it means i can't use the standard error-messages table from, the master database which i use for the errors from Stored procedures and triggers.

Maybe i should moce those errors to the same table ...

thanks again!
B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top