Red Gate forums :: View topic - How to catch a double SQL error when deploying a Foreign Key
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Packager 6
SQL Packager 6 forum

How to catch a double SQL error when deploying a Foreign Key

Search in SQL Packager 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
Ozzie



Joined: 26 Jun 2007
Posts: 14
Location: Havertown, PA, USA

PostPosted: Tue Mar 22, 2011 5:19 pm    Post subject: How to catch a double SQL error when deploying a Foreign Key Reply with quote

Here's an instance.

If you go to add a Foreign key to a child table where the referenced column in the parent table is not a primary key, you will receive 2 errors.

Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'Mosaic.dbo.ProgramRecoType' that match the referencing column list in the foreign key 'FK_ProviderServiceCountryRecommendation_ProgramRecoType_ProgramRecoType_ID_ProgramRecoType_ID'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

If you try/catch - you only catch the second error - resulting in the display of
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

Which does me no good? Is there actually a way to catch this when deploying scripts?

Doug
Back to top
View user's profile Send private message
james.billings



Joined: 16 Jun 2010
Posts: 1144
Location: My desk.

PostPosted: Wed Mar 23, 2011 8:19 pm    Post subject: Reply with quote

Thanks for posting.

I'm guessing you're building a C# project from packager and you want to be able to catch the first error in that?

I'm not immediately sure off the top of my head. I imagine it's something to do with the way SQL Server executes the statements and returns the errors. You might want to see if the InnerException contains anything further... but I'll see if I can set up a replication here to try it out on myself
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group