Constraint matches constraint named Constraint1 already in collect

G

Guest

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.dataSetFrmMain)).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 :)
 
G

Guest

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.ActiveOffers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Offers)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.dataSetFrmMain)).EndInit();

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

Thank me very much..

....
 
S

Steven Brewer

I had same problem as the original poster of this thread.
The really odd thing was that I renamed my contraints, and the Error was referring to contraint that no longer existed!

Your solution of moving the EndInit down worked.
Thanks.



Ta wrote:

Constraint matches constraint named Constraint1 already in collect
31-May-07

Hi, first of all, I'm using

Microsoft Visual Studio 200
Version 8.0.50727.762 (SP.050727-7600
Microsoft .NET Framewor
Version 2.0.5072

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.dataSetFrmMain)).EndInit()

I get an exception
System.Data.DataException was unhandle
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 :)

Previous Posts In This Thread:

Constraint matches constraint named Constraint1 already in collect
Hi, first of all, I'm using

Microsoft Visual Studio 200
Version 8.0.50727.762 (SP.050727-7600
Microsoft .NET Framewor
Version 2.0.5072

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.dataSetFrmMain)).EndInit()

I get an exception
System.Data.DataException was unhandle
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 :)

The thing is, that for some strange reason the constraints names are not set
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.ActiveOffers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Offers)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.dataSetFrmMain)).EndInit();

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

Thank me very much..

....


Submitted via EggHeadCafe - Software Developer Portal of Choice
IIS 7.0 Extensionless UrlRewriting (Short urls)
http://www.eggheadcafe.com/tutorial...df-52898c6aa5d7/iis-70-extensionless-url.aspx
 
S

Steven Brewer

FYI: Oh yeah, I am using VS 2008 Version 9.0.30729.1 SP



Steven Brewer wrote:

Thanks again!
26-Apr-10

I had same problem as the original poster of this thread.
The really odd thing was that I renamed my contraints, and the Error was referring to contraint that no longer existed!

Your solution of moving the EndInit down worked.
Thanks.

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Get Silverlight 4 Installed: Tips and Tricks
http://www.eggheadcafe.com/tutorial...b-f54c56a64ed9/get-silverlight-4-install.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top