Failed to enable constraints error...

  • Thread starter Thread starter Robb Sadler
  • Start date Start date
R

Robb Sadler

I have created a dataset which contains a parent child
relationship based on a date, machine and batch number.

After creating the batch (parent) record,

pseudo:
new dataset
new parentdataadapter
new childdataadapter

select stmt for parent for one record


I am able to successfully create a child record by opening
a dataset and first retrieving the batch record, and then
creating a child record. However, when I attempt to read
the record I just created, I get the following error:

"Failed to enable constraints. One or more rows contain
values violating non-null, unique, or foreign-key
constraints."

This record just passed the constraints when I wrote it?!?!

I have double checked the key values and they match the
parent record. I retrieved the parent record they
associate with into the dataset before retrieving the
child records. I can't see why this error is coming up.

If someone has an "Oh yeah," that would be helpful. I can
pull this code out and rework it as a small package if
required, but since I have strongly typed datasets, and
the table relationships, etc, I figured it is not easily
reproduced.
 
Hi Robb,

I cannot reproduce it on my machine according to your statement. I'm not
quite sure how did you read the record. I would be glad to see the small
package you built. Please send it to me if you can. Remove "online" from
the email shown on screen is my mail address.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Robb Sadler" <[email protected]>
| Sender: "Robb Sadler" <[email protected]>
| Subject: Failed to enable constraints error...
| Date: Fri, 24 Oct 2003 11:24:33 -0700
| Lines: 34
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOaXBKUBWhLkdUTQ1mHrGx/5l06xg==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64506
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| I have created a dataset which contains a parent child
| relationship based on a date, machine and batch number.
|
| After creating the batch (parent) record,
|
| pseudo:
| new dataset
| new parentdataadapter
| new childdataadapter
|
| select stmt for parent for one record
|
|
| I am able to successfully create a child record by opening
| a dataset and first retrieving the batch record, and then
| creating a child record. However, when I attempt to read
| the record I just created, I get the following error:
|
| "Failed to enable constraints. One or more rows contain
| values violating non-null, unique, or foreign-key
| constraints."
|
| This record just passed the constraints when I wrote it?!?!
|
| I have double checked the key values and they match the
| parent record. I retrieved the parent record they
| associate with into the dataset before retrieving the
| child records. I can't see why this error is coming up.
|
| If someone has an "Oh yeah," that would be helpful. I can
| pull this code out and rework it as a small package if
| required, but since I have strongly typed datasets, and
| the table relationships, etc, I figured it is not easily
| reproduced.
|
 
Hi Robb,

There doesn't seem to be problems in your code. However, i cannot reproduce
it, because I don't have the database. I think you can try some steps for
trouble shooting.

1. Please verify if the strong typed dataset schema is the same as the
schema of the database table. (Did you create the dataset by simply drag
the table from the server explorer or did you made some changes to it?) If
you have made some changes, the schema might be different, so that it might
violate the constrants.

2. Try to substitute the following code with a single
SqlCommand.ExecuteScalar. ExecuteScalar returns the first cell of the first
row of the first table. If nothing returned from the database, it returns a
DBNull value.

daDoc.SelectCommand = new SqlCommand(myQuery, icConn);
daDoc.Fill(dsDoc, 0, 1, TblName);

// dsDoc should now have the record containing the highest scan
sequence so we can return it to the caller
if (dsDoc.Tables.Count > 0)
if (dsDoc.Tables[0].Rows.Count > 0)
return (int)dsDoc.Tables[TblName].Rows[0]["ScanSeq"];

You can use:

return selectcommand.ExecuteScalar();

This might be a workaround.

If it still doesn't work, you can post your database table script here. (To
get the table script, click on the table in SQL server, press Ctrl+C, and
press Ctrl+V in a text editer such as notepad.)

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| X-Tomcat-ID: 102372277
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Kevin Yu [MSFT])
| Organization: Microsoft
| Date: Sat, 25 Oct 2003 07:16:51 GMT
| Subject: RE: Failed to enable constraints error...
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Lines: 63
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64530
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Robb,
|
| I cannot reproduce it on my machine according to your statement. I'm not
| quite sure how did you read the record. I would be glad to see the small
| package you built. Please send it to me if you can. Remove "online" from
| the email shown on screen is my mail address.
|
| Kevin Yu
| =======
| "This posting is provided "AS IS" with no warranties, and confers no
| rights."
|
| --------------------
| | Content-Class: urn:content-classes:message
| | From: "Robb Sadler" <[email protected]>
| | Sender: "Robb Sadler" <[email protected]>
| | Subject: Failed to enable constraints error...
| | Date: Fri, 24 Oct 2003 11:24:33 -0700
| | Lines: 34
| | Message-ID: <[email protected]>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="iso-8859-1"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Thread-Index: AcOaXBKUBWhLkdUTQ1mHrGx/5l06xg==
| | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| | Newsgroups: microsoft.public.dotnet.framework.adonet
| | Path: cpmsftngxa06.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.adonet:64506
| | NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| |
| | I have created a dataset which contains a parent child
| | relationship based on a date, machine and batch number.
| |
| | After creating the batch (parent) record,
| |
| | pseudo:
| | new dataset
| | new parentdataadapter
| | new childdataadapter
| |
| | select stmt for parent for one record
| |
| |
| | I am able to successfully create a child record by opening
| | a dataset and first retrieving the batch record, and then
| | creating a child record. However, when I attempt to read
| | the record I just created, I get the following error:
| |
| | "Failed to enable constraints. One or more rows contain
| | values violating non-null, unique, or foreign-key
| | constraints."
| |
| | This record just passed the constraints when I wrote it?!?!
| |
| | I have double checked the key values and they match the
| | parent record. I retrieved the parent record they
| | associate with into the dataset before retrieving the
| | child records. I can't see why this error is coming up.
| |
| | If someone has an "Oh yeah," that would be helpful. I can
| | pull this code out and rework it as a small package if
| | required, but since I have strongly typed datasets, and
| | the table relationships, etc, I figured it is not easily
| | reproduced.
| |
|
|
 
-----Original Message-----
Hi Robb,

There doesn't seem to be problems in your code. However,
i cannot reproduce it, because I don't have the database.

Hi Kevin,

I agree that it doesn't seem to be bad code, but
something in there must be messed up. I can't imagine
that this is way off the beaten path of development.

The pkg I sent included create scripts that could be run
against a database to make a test table which can be
cleanly deleted when you are done.

You can use any database you like, as the script creates
a separate table. Just create a DB and make sure the
connect string matches the name you use.

I spent a couple of hours detaching this problem from my
development and putting it into a reproducable package at
your request. I sure hope you will give me a hand.

For any other takers, the zip file can be found at:
http://www.mrgiga.com/TestScenario/TestScenario.zip

I appreciate any and all help on this seemingly simple
thing!

All you have to do is:
1. Run query analyzer, select the database you want to
use, and run this script to create the table.
2. Change the connect string in the code to hook up to
where your database is sitting.
3. Run the program.
4. Press the insert record button
5. Press the retrieve record button.

I followed my own instructions that I sent you and
successfully created the database and recreated the issue
twice here to make sure I wasn't wasting any of your
time...

Robb Sadler
 
OK, I found out what is happening.

When I query the table and ask for one column back it is
returning two tables back through the adapter. I was
looking for the column in the table first indexed by 0
which I thought would be OK since I figured only one
table would come back. Then I used the name of the source
table. Neither of these work because the source table
does come back through (probably because its a strongly
types dataaset), and an additional table comes through
with the column I requested. So when I chanegd the code
thusly (is that a word?):

DataAdapter: daDoc Dataset: dsDoc

daDoc.Fill(dsDoc, "Temp");
return (int)dsDoc.Tables["Temp"].Rows[0]["ScanSeq"];

then it worked...

Thanks for trying...

Regards to all,

Robb

daDoc.Fill
 
Hi Robb,

I'm glad to know that you've resolved the problem. Thanks for using MSDN
Newsgroup. If you have any questions, please feel free to write a new post
in the newsgroup.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: <[email protected]>
| Sender: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: Failed to enable constraints error...
| Date: Tue, 28 Oct 2003 10:01:26 -0800
| Lines: 83
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOdfYGZWr84alLJR72PYJ22/5mdVA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64758
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| OK, I found out what is happening.
|
| When I query the table and ask for one column back it is
| returning two tables back through the adapter. I was
| looking for the column in the table first indexed by 0
| which I thought would be OK since I figured only one
| table would come back. Then I used the name of the source
| table. Neither of these work because the source table
| does come back through (probably because its a strongly
| types dataaset), and an additional table comes through
| with the column I requested. So when I chanegd the code
| thusly (is that a word?):
|
| DataAdapter: daDoc Dataset: dsDoc
|
| daDoc.Fill(dsDoc, "Temp");
| return (int)dsDoc.Tables["Temp"].Rows[0]["ScanSeq"];
|
| then it worked...
|
| Thanks for trying...
|
| Regards to all,
|
| Robb
|
| daDoc.Fill
|
|
| >-----Original Message-----
| >
| >>-----Original Message-----
| >>Hi Robb,
| >>
| >>There doesn't seem to be problems in your code.
| However,
| >i cannot reproduce it, because I don't have the
| database.
| >
| >Hi Kevin,
| >
| >I agree that it doesn't seem to be bad code, but
| >something in there must be messed up. I can't imagine
| >that this is way off the beaten path of development.
| >
| >The pkg I sent included create scripts that could be run
| >against a database to make a test table which can be
| >cleanly deleted when you are done.
| >
| >You can use any database you like, as the script creates
| >a separate table. Just create a DB and make sure the
| >connect string matches the name you use.
| >
| >I spent a couple of hours detaching this problem from my
| >development and putting it into a reproducable package
| at
| >your request. I sure hope you will give me a hand.
| >
| >For any other takers, the zip file can be found at:
| >http://www.mrgiga.com/TestScenario/TestScenario.zip
| >
| >I appreciate any and all help on this seemingly simple
| >thing!
| >
| >All you have to do is:
| >1. Run query analyzer, select the database you want to
| >use, and run this script to create the table.
| >2. Change the connect string in the code to hook up to
| >where your database is sitting.
| >3. Run the program.
| >4. Press the insert record button
| >5. Press the retrieve record button.
| >
| >I followed my own instructions that I sent you and
| >successfully created the database and recreated the
| issue
| >twice here to make sure I wasn't wasting any of your
| >time...
| >
| >Robb Sadler
| >
| >.
| >
|
 
Back
Top