[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

Sql server error number is the same for "Forignkey" And "check Constraint"

Hello
am little confused , i know that errors in sql server has  A number code ,  but the problem is
the error Number is same in Foriegn Key Violation and in  conflicted with the CHECK constraint
both of them has the same error Number  547
so when i try to violate the foringn key constraint it comes with the error as following
Msg 547, Level 16, State 0
also when i try to confilct with check constraint i recieve the same error number
Msg 547, Level 16, State 0

My problem is these number is important for me because i use it form my vb.net app. to  handle the error and raise an friendly error message to the user
1-Can you help me and tell me why is this happen ?
2-Can you give me a link to all SQL server Errors numbers/code because i searched and i didnt find
0
ali_alannah
Asked:
ali_alannah
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>1-Can you help me and tell me why is this happen ?
 foreign key IS a check contraint.

>2-Can you give me a link to all SQL server Errors numbers/code because i searched and i didnt find
http://www.microsoft.com/technet/support/ee/ee_advanced.aspx

or, in sql server, you have the table sysmessages:
http://technet.microsoft.com/en-us/library/ms177546.aspx
0
 
ali_alannahAuthor Commented:
Hello angelIII:
You post very helpfull but Please guide me and tell mh if i want to diffretiate between Forigkn key violation and the Check constraint confilct , to raise a friendly error message to the user
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to differentiate, you have to check the error text/description.
which is "dangerous", as if ever the language setting of the login is changed, the text might change also.

now, with due respect:
is your project that advanced/complete that you have to "bother" such subtle differences in what exactly the user is reported as error message?
especially foreign key constraints should "never" be violated by a application, given the user only those choices that cannot violate the foreign key constraints ...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now