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

N

nadeem_far

Hello Everyone,

We have a .net application (1.1 Framework) that uses a strongly typed
dataset.
The application is in production for over 2 years.

One of the users recently reported that when he tried starting the
app. in the morning it failed and the logs showed the following error
details. After like 10 minutes or so he double clicks the app. and it
starts up with no errors.

I have tried searching on this issue and most of the threads\articles
discuss this issue in development environment. Has any one faced this
issue in production environment and most of all how to fix this
strange error.?.

The Typed dataset in question has two table only in a Master-Detail
relationship.


Source: System.Data
Message: Failed to enable constraints. One or more rows contain values
violating non-null, unique, or foreign-key constraints.
Stack Trace: at System.Data.DataSet.FailedEnableConstraints()
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at System.Data.Common.DbDataAdapter.FillFromReader(Object data,
String srcTable, IDataReader dataReader, Int32 startRecord, Int32
maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data,
Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Company.DataLayer.API.Database.CreateTradeCache(String
ProductID, String reportID)
at Company.DataLayer.API.Database.CreateReportCache(String
ProductID, String reportID)
at Company.DataLayer.API.Database.CreateUserCache(String userName)
at Company.DataLayer.API.Database.Login(String userName, Boolean
NotificationRequired)


Any help will be appreciated.

Nadeem
 
M

Marina Levit [MVP]

Is there a way to know what data is in the dataset at the time? Perhaps
there is an error retrieving the data, but something the application is
doing is causing this error instead.

What do the tiers look like in your app? Perhaps there is a tier making a
call to another tier but the call is timing out because ASP.NET is starting?
And then the error being shown is a result of not being able to retrieve the
data and something else happening.
 
R

Rad [Visual C# MVP]

Hello Everyone,

We have a .net application (1.1 Framework) that uses a strongly typed
dataset.
The application is in production for over 2 years.

One of the users recently reported that when he tried starting the
app. in the morning it failed and the logs showed the following error
details. After like 10 minutes or so he double clicks the app. and it
starts up with no errors.

I have tried searching on this issue and most of the threads\articles
discuss this issue in development environment. Has any one faced this
issue in production environment and most of all how to fix this
strange error.?.

The Typed dataset in question has two table only in a Master-Detail
relationship.

Source: System.Data
Message: Failed to enable constraints. One or more rows contain values
violating non-null, unique, or foreign-key constraints.
Stack Trace: at System.Data.DataSet.FailedEnableConstraints()
at System.Data.DataSet.EnableConstraints()
at System.Data.DataSet.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at System.Data.Common.DbDataAdapter.FillFromReader(Object data,
String srcTable, IDataReader dataReader, Int32 startRecord, Int32
maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data,
Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Company.DataLayer.API.Database.CreateTradeCache(String
ProductID, String reportID)
at Company.DataLayer.API.Database.CreateReportCache(String
ProductID, String reportID)
at Company.DataLayer.API.Database.CreateUserCache(String userName)
at Company.DataLayer.API.Database.Login(String userName, Boolean
NotificationRequired)

Any help will be appreciated.

Nadeem

That error is pretty much as simple as it sounds ... some of the data being
pushed into the dataset violates one or more of the constraints -- foreign
key or not null.

In your application logic do you make use of transactions? Perhaps the
problem is due to the fact that some complicated transaction has only been
partially completed, or some user input is simply invalid
 
N

nadeem_far

That error is pretty much as simple as it sounds ... some of the data being
pushed into the dataset violatesoneormoreof theconstraints--foreignkeyor not null.

In your application logic do you make use of transactions? Perhaps the
problem is due to the fact that some complicated transaction has only been
partially completed, or some user input is simply invalid


Hi Marina\Rad,

This is a windows app. The queries are running in the data tier.

And no, there are no transactions involved in this part of the code.
Here is how its working

1. We have a Trade and products in a trade.
2. We clear out the product detials table.
3. Clear out the trade table.
4. run the select on the trade table to get all the trades.
5. run the select to get all the products for each trade.

Also please note, we have a highly controlled production environment.
All this happened in the morning when the user tried to load the app.

Hope this is helpful.

Thanks,

Nad
 
R

Rad [Visual C# MVP]

Hi Marina\Rad,

This is a windows app. The queries are running in the data tier.

And no, there are no transactions involved in this part of the code.
Here is how its working

1. We have a Trade and products in a trade.
2. We clear out the product detials table.
3. Clear out the trade table.
4. run the select on the trade table to get all the trades.
5. run the select to get all the products for each trade.

Also please note, we have a highly controlled production environment.
All this happened in the morning when the user tried to load the app.

Hope this is helpful.

Thanks,

Nad

Well, i'm of the impression that some of your queries are populating the
dataset with values that violate some of the constraints set. A quick and
dirty solution (only as a last resort!) is to set the EnforceConstraints
property of the dataset to false
 

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