473,473 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Constraint matches constraint named Constraint1 already in collect

Hi, first of all, I'm using:

Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: C# Express.

I have added a DataSet to my Form manually and also manually populated it
with tables (columns and primary keys), and Relations.

At first all was working well, but after I extended my DataSet to include
more tables and relations my application wouldn't run anymore because as soon
as InitializeComponent() of the main form gets to this line:

((System.ComponentModel.ISupportInitialize)(this.d ataSetFrmMain)).EndInit();

I get an exception:
System.Data.DataException was unhandled
Message="Constraint matches constraint named Constraint1 already in
collection."
Source="System.Data"
StackTrace:etc..

After some investigating I figured out that the designer generated code for
my dataset named every unique primary key constraint "Constraint1". To see
this one would select the dataset, open its properties window, pick tables,
select one and view the Constraints property. There you can manually edit the
Constraint name, which I did for all my PK constraints. Also note that you
have to remove (and later recreate) all FK constraints that rely on a given
PK before you can do that (a tedious process may I note). Then all was
working well again.

The next time I wanted to extend my dataset (that be now) I found my self
facing the same nice little exception. I removed every PK and relation. Then
I went on to add them again (there you can see for yourself that as you add a
PK to a table the designer conveniently names every PK constraint
"Constraint1", and the application runs normally regardless. However, when
you add Relations, the runtime suddenly realizes all its unique PK
constraints are named the same and everything crashes.

On top of it all, try just to change the constraints names from
"Constraint1" to whatever, leave it with just the PK's there, don't add any
relations, save, exit VS and reload. Surprise! Every constraint is named
"Constraint1" again! The problem must be somewhere therein.

Can this be fixed or am I condemned to eternal renaming of my constraints?

Thank you very much :)
May 31 '07 #1
1 4341
The thing is, that for some strange reason the constraints names are not set
until tables EndInit() method is called. So to fix this problem put the
datasets EndInit() call after all of the tables endinits.. like so:

....
((System.ComponentModel.ISupportInitialize)(this.A ctiveOffers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.O ffers)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.d ataSetFrmMain)).EndInit();

The designer generated call places the datasets endinit() first..

Thank me very much..

....
Jun 1 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yongsing | last post by:
I have two tables as shown below (only relevant columns shown). The second table is dependent on the first one. CREATE TABLE PARENTTABLE ( ... SERIAL CHAR(12) NOT NULL, ENDDATE TIMESTAMP NOT...
7
by: Brian Keating | last post by:
Hi there, Is it possible to add a unique constraint on two columns in a table, so that the constraint is a composite of the two? i.e. these two columns together should be unique...? i.e....
1
by: | last post by:
Hi, I am getting the following error when I run my Visual Basic application: "Cannot add primary key constraint since primary key is already set for the table" I am using datasets with...
4
by: Jethro Guo | last post by:
C++ template use constraint by signature,It's very flexible to programmer but complex for complier, and at most time programmer can not get clear error message from complier if error occur. C#...
3
by: Jeff Kish | last post by:
Hi. I'm getting errors like this when I try to run an upgrade script I'm trying to write/test: altering labels to length 60 Server: Msg 5074, Level 16, State 4, Line 5 The object...
8
by: bob | last post by:
I am writing some code to create new tables in a SQL database. However, I don't want to try to create a table if it already exists. How can I test beforehand to see if a particular named table...
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
3
by: DBC User | last post by:
Hi all, I would like to know is there a way to find out if any named pipes are running in a box. How can I go about doing that? Or is there a way to find out if a particular named pipe already...
0
by: frodenekkoy | last post by:
Hi! Have a dataset that I need to populate with 4 datatables. The name of the datatables needs to be Tag2. This is because I need to return the data as xml in this specific format...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.