Hi,

I'm loading a dataset from a cached viewstate version of the dataset created
on a previous http request. When I read the call ReadXml on the typed
dataset, I get:
"Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints"
I suspect this is due to a field in one of the tables which can be null, but
if it is not null it is a foreign key to another dataset table. At present
the field in this table is null (in the database).

What attributes of the dataset table field, or the dataset constraint should
I set to indicate null values don't violate the constraint?

Thanks
Martin

Re: Dataset constraint violoation with null foreign key value by Miha

Miha
Thu Jun 17 04:54:46 CDT 2004

Hi Martin,

DataColumn.AllowDBNull perhaps.
BTW, to find out which row is causing errors, just iterate through all rows
and check DataRow.HasErrors and RowError properites.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Martin" <x@y.z> wrote in message
news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I'm loading a dataset from a cached viewstate version of the dataset
created
> on a previous http request. When I read the call ReadXml on the typed
> dataset, I get:
> "Failed to enable constraints. One or more rows contain values violating
> non-null, unique, or foreign-key constraints"
> I suspect this is due to a field in one of the tables which can be null,
but
> if it is not null it is a foreign key to another dataset table. At
present
> the field in this table is null (in the database).
>
> What attributes of the dataset table field, or the dataset constraint
should
> I set to indicate null values don't violate the constraint?
>
> Thanks
> Martin
>
>



Re: Dataset constraint violoation with null foreign key value by Martin

Martin
Thu Jun 17 06:04:59 CDT 2004

Hi Miha,

Sounds good. I don't see that property reflected in the properties for the
field element in my typed dataset. I'm looking at the xsd file in vs.net

??

Martin
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:%23YlPrKFVEHA.3944@tk2msftngp13.phx.gbl...
> Hi Martin,
>
> DataColumn.AllowDBNull perhaps.
> BTW, to find out which row is causing errors, just iterate through all
rows
> and check DataRow.HasErrors and RowError properites.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Martin" <x@y.z> wrote in message
> news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> > Hi,
> >
> > I'm loading a dataset from a cached viewstate version of the dataset
> created
> > on a previous http request. When I read the call ReadXml on the typed
> > dataset, I get:
> > "Failed to enable constraints. One or more rows contain values violating
> > non-null, unique, or foreign-key constraints"
> > I suspect this is due to a field in one of the tables which can be null,
> but
> > if it is not null it is a foreign key to another dataset table. At
> present
> > the field in this table is null (in the database).
> >
> > What attributes of the dataset table field, or the dataset constraint
> should
> > I set to indicate null values don't violate the constraint?
> >
> > Thanks
> > Martin
> >
> >
>
>



Re: Dataset constraint violoation with null foreign key value by Martin

Martin
Thu Jun 17 08:16:58 CDT 2004

I have tried setting EnforceConstraints false before doing ReadXml, and then
setting EnforceConstraints true after ReadXml, incase the dataset was being
populated in an order that created the problem - no success.

I also set EnforceConstraints true just before serialising the original
dataset to a string, in case it was breaking constraints there but not
reporting it. Constraints are fine at this point.

So it seems to be something to do with the (de)serialisation of the dataset

Code to serialise is
myDS.EnforceConstraints=true;
System.IO.StringWriter sw = new System.IO.StringWriter();
myDS.WriteXml(sw);
ViewState["myDS"] = sw.ToString();

To deserialise is:

System.IO.StringReader sr = new
System.IO.StringReader((string)(ViewState["MyDS"]));
myDS.EnforceConstraints=false;
myDS.ReadXml(sr);
myDS.EnforceConstraints=true; // exception thrown here

"Martin" <x@y.z> wrote in message
news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I'm loading a dataset from a cached viewstate version of the dataset
created
> on a previous http request. When I read the call ReadXml on the typed
> dataset, I get:
> "Failed to enable constraints. One or more rows contain values violating
> non-null, unique, or foreign-key constraints"
> I suspect this is due to a field in one of the tables which can be null,
but
> if it is not null it is a foreign key to another dataset table. At
present
> the field in this table is null (in the database).
>
> What attributes of the dataset table field, or the dataset constraint
should
> I set to indicate null values don't violate the constraint?
>
> Thanks
> Martin
>
>



Re: Dataset constraint violoation with null foreign key value by Martin

Martin
Thu Jun 17 09:03:17 CDT 2004

I've tried setting AllowDBNull for the Dataset, but that's made no
difference.

I have now set NullValue for the field that can be null in the xsd file for
the dataset. This seems to have broken vs.net. I am now getting "The
custom tool 'MSDataSetGenerator' failed while processing file myDS.xsd"

Can't seem to unbreak it :-(

Martin

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:%23YlPrKFVEHA.3944@tk2msftngp13.phx.gbl...
> Hi Martin,
>
> DataColumn.AllowDBNull perhaps.
> BTW, to find out which row is causing errors, just iterate through all
rows
> and check DataRow.HasErrors and RowError properites.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "Martin" <x@y.z> wrote in message
> news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> > Hi,
> >
> > I'm loading a dataset from a cached viewstate version of the dataset
> created
> > on a previous http request. When I read the call ReadXml on the typed
> > dataset, I get:
> > "Failed to enable constraints. One or more rows contain values violating
> > non-null, unique, or foreign-key constraints"
> > I suspect this is due to a field in one of the tables which can be null,
> but
> > if it is not null it is a foreign key to another dataset table. At
> present
> > the field in this table is null (in the database).
> >
> > What attributes of the dataset table field, or the dataset constraint
> should
> > I set to indicate null values don't violate the constraint?
> >
> > Thanks
> > Martin
> >
> >
>
>



Re: Dataset constraint violoation with null foreign key value by Martin

Martin
Thu Jun 17 10:38:21 CDT 2004

I've unbroken the MSDataSetGenerator by removing the NullValue attribute in
the XML view of msDS.xsd.

Still stuck on constraint execption violation after deserialising my
dataset.

Anyone?
Martin

"Martin" <x@y.z> wrote in message
news:OliHANHVEHA.1952@TK2MSFTNGP12.phx.gbl...
> I've tried setting AllowDBNull for the Dataset, but that's made no
> difference.
>
> I have now set NullValue for the field that can be null in the xsd file
for
> the dataset. This seems to have broken vs.net. I am now getting "The
> custom tool 'MSDataSetGenerator' failed while processing file myDS.xsd"
>
> Can't seem to unbreak it :-(
>
> Martin
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:%23YlPrKFVEHA.3944@tk2msftngp13.phx.gbl...
> > Hi Martin,
> >
> > DataColumn.AllowDBNull perhaps.
> > BTW, to find out which row is causing errors, just iterate through all
> rows
> > and check DataRow.HasErrors and RowError properites.
> >
> > --
> > Miha Markic [MVP C#] - RightHand .NET consulting & development
> > miha at rthand com
> > www.rthand.com
> >
> > "Martin" <x@y.z> wrote in message
> > news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> > > Hi,
> > >
> > > I'm loading a dataset from a cached viewstate version of the dataset
> > created
> > > on a previous http request. When I read the call ReadXml on the typed
> > > dataset, I get:
> > > "Failed to enable constraints. One or more rows contain values
violating
> > > non-null, unique, or foreign-key constraints"
> > > I suspect this is due to a field in one of the tables which can be
null,
> > but
> > > if it is not null it is a foreign key to another dataset table. At
> > present
> > > the field in this table is null (in the database).
> > >
> > > What attributes of the dataset table field, or the dataset constraint
> > should
> > > I set to indicate null values don't violate the constraint?
> > >
> > > Thanks
> > > Martin
> > >
> > >
> >
> >
>
>



Re: Dataset constraint violoation with null foreign key value by Miha

Miha
Thu Jun 17 15:10:38 CDT 2004

Hi Martin,

Did you try iterating through rows and tables (HasErrors) to see where the
problem is?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Martin" <x@y.z> wrote in message
news:eR3WHzGVEHA.584@TK2MSFTNGP09.phx.gbl...
> I have tried setting EnforceConstraints false before doing ReadXml, and
then
> setting EnforceConstraints true after ReadXml, incase the dataset was
being
> populated in an order that created the problem - no success.
>
> I also set EnforceConstraints true just before serialising the original
> dataset to a string, in case it was breaking constraints there but not
> reporting it. Constraints are fine at this point.
>
> So it seems to be something to do with the (de)serialisation of the
dataset
>
> Code to serialise is
> myDS.EnforceConstraints=true;
> System.IO.StringWriter sw = new System.IO.StringWriter();
> myDS.WriteXml(sw);
> ViewState["myDS"] = sw.ToString();
>
> To deserialise is:
>
> System.IO.StringReader sr = new
> System.IO.StringReader((string)(ViewState["MyDS"]));
> myDS.EnforceConstraints=false;
> myDS.ReadXml(sr);
> myDS.EnforceConstraints=true; // exception thrown here
>
> "Martin" <x@y.z> wrote in message
> news:u%232ZDWEVEHA.3656@TK2MSFTNGP11.phx.gbl...
> > Hi,
> >
> > I'm loading a dataset from a cached viewstate version of the dataset
> created
> > on a previous http request. When I read the call ReadXml on the typed
> > dataset, I get:
> > "Failed to enable constraints. One or more rows contain values violating
> > non-null, unique, or foreign-key constraints"
> > I suspect this is due to a field in one of the tables which can be null,
> but
> > if it is not null it is a foreign key to another dataset table. At
> present
> > the field in this table is null (in the database).
> >
> > What attributes of the dataset table field, or the dataset constraint
> should
> > I set to indicate null values don't violate the constraint?
> >
> > Thanks
> > Martin
> >
> >
>
>