Failed to Enable Constraints. One or More Rows Contain Values Violating Non-Null, Unique, or Foreign-Key Constraints

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

This problem is usually caused by one of the following

  • null values being returned for columns not set to AllowDBNull
  • duplicate rows being returned with the same primary key.
  • a mismatch in column definition (e.g. size of char fields) between the database and the dataset

Try running your query natively and look at the results, if the resultset is not too large. If you've eliminated null values, then my guess is that the primary key columns is being duplicated.

Or, to see the exact error, you can manually add a Try/Catch block to the generated code like so and then breaking when the exception is raised:

Sample Image

Then within the command window, call GetErrors method on the table getting the error.

For C#, the command would be ? dataTable.GetErrors()

For VB, the command is ? dataTable.GetErrors

Sample Image

This will show you all datarows which have an error. You can get then look at the RowError for each of these, which should tell you the column that's invalid along with the problem. So, to see the error of the first datarow in error the command is:

? dataTable.GetErrors(0).RowError

or in C# it would be ? dataTable.GetErrors()[0].RowError

Sample Image

How do I fix the error: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints

UIPath may produce this error when you try to run a query
“Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints”

The query may work in the command line of the database but not in UIPath but this is deceptive as this is NOT a UIPath issue. It is an issue with the database table itself. The table elements must be a type that UIPath can use.

For instance, one of the issues documented:
SQLite will allow you to create the database table like this
Ø create table clients (name text null, email text null, goodstanding text null);
While this is allowable in the database and it will work, UIPath will not be able to read these rows. Instead, create the table like this:
Ø create table clients (name string null, email string null, goodstanding string null);

UIPath will not know how to handle a variable type “text”

Once you make the table of type string (or other accepted varialbes int, etc) you will be able to use this in UIPath

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. asp.net c#

Follow the steps given below:

This actually worked for me, hope even you able to clear.

  1. Go to the dataset and copy the query of GetGridDataBy.
  2. Now go back to the main dataset window and delete the GetGridDataBy query from the list.
  3. Now ADD new query and paste the query details which you have copied from the previous GetGridDataBy query.
  4. And now name it something else like GetGridDataBy2
  5. Replace all the GetGridDataBy from the code behind with GetGridDataBy2.
  6. And then Run.

Sometimes this error occurs due to malfunction under auto-generation of signature code. This steps will help you resolve this issue. All the best!

Failed to enable constraints when filling datatable

Fixed it myself: The table adapter had all the fields in the data set, but my query only had some of the fields in the table adapter. I changed the table adapter to use the query of interest, and the problem was resolved.

Therefore, the constraint violation was most likely null data in NOT NULL fields.

Failed to enable constraints. When using a data table adapter

Looks to me that your query is returning several records with the same product_id and the table adapter expects only unique rows. I am pretty sure you can disable the behavior by setting EnforceConstraints to false.

DataTable.Load, One or more rows contain values violating non-null, unique, or foreign-key constraints

I managed to solve this by getting the schema of the table, iterating through the rows of the schema table (which are columns of the actual table) and creating a column with same properties as the schema column (only difference is setting new column's AllowDBNull to true and Unique and AutoIncrement to false) and finally adding the new column to a fresh datatable which will later be filled with data of our actual table (by the help of a DataReader to get only data and not the schema).

Here is the code:

using (SqlCeConnection C = new SqlCeConnection(DBStr))
using (Cmd)
{ //using SqlCeCommand
Cmd.Connection = C;
C.Open();
using (SqlCeDataReader Rdr = Cmd.ExecuteReader())
{
//Create datatable to hold schema and data seperately
//Get schema of our actual table
DataTable DTSchema = Rdr.GetSchemaTable();
DataTable DT = new DataTable();
if (DTSchema != null)
if (DTSchema.Rows.Count > 0)
for (int i = 0; i < DTSchema.Rows.Count; i++)
{
//Create new column for each row in schema table
//Set properties that are causing errors and add it to our datatable
//Rows in schema table are filled with information of columns in our actual table
DataColumn Col = new DataColumn(DTSchema.Rows[i]["ColumnName"].ToString(), (Type)DTSchema.Rows[i]["DataType"]);
Col.AllowDBNull = true;
Col.Unique = false;
Col.AutoIncrement = false;
DT.Columns.Add(Col);
}

while (Rdr.Read())
{
//Read data and fill it to our datatable
DataRow Row = DT.NewRow();
for (int i = 0; i < DT.Columns.Count; i++)
{
Row[i] = Rdr[i];
}
DT.Rows.Add(Row);
}
//This is our datatable filled with data
return DT;
}
}


Related Topics



Leave a reply



Submit