Solved

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

Posted on 2008-06-22
3
684 Views
Last Modified: 2009-12-16
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
Comment
Question by:ali_alannah
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 21840204
>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
 

Author Comment

by:ali_alannah
ID: 21841960
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21842001
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now