I make an outer join and executed successfully in the informix
database but I get the following exception in my code:
DataTable dt = TeachingLoadDAL.GetCoursesWithEvalState(i, bat);
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I know the problem, but I don't know how to fix it.
The second table I make the outer join on contains a composite primary key which are null in the previous outer join query.
EDIT:
SELECT UNIQUE a.crs_e, a.crs_e || '/ ' || a.crst crs_name, b.period,
b.crscls, c.crsday, c.from_lect, c.to_lect,
c.to_lect - c.from_lect + 1 Subtraction, c.lect_kind, e.eval, e.batch_no,
e.crsnum, e.lect_code, e.prof_course
FROM rlm1course a, rfc14crsgrp b, ckj1table c, mnltablelectev d,
OUTER(cc1assiscrseval e)
WHERE a.crsnum = b.crsnum
AND b.crsnum = c.crsnum
AND b.crscls = c.crscls
AND b.batch_no = c.batch_no
AND c.serial_key = d.serial_key
AND c.crsnum = e.crsnum
AND c.batch_no = e.batch_no
AND d.lect_code= e.lect_code
AND d.lect_code = ....
AND b.batch_no = ....
The problem happens with the table cc1assiscrseval
. The primary key is (batch_no, crsnum, lect_code).
How to fix this problem?
EDIT:
According to @PaulStock
advice:
I do what he said, and i get:
? dt.GetErrors()[0] {System.Data.DataRow} HasErrors: true ItemArray: {object[10]} RowError: "Column 'eval' does not allow DBNull.Value."
So I solve my problem by replacing e.eval
to ,NVL (e.eval,'') eval
.and this solves my problem.
Thanks a lot.
To fix this error, i took off the troubling table adapter from the Dataset designer, and saved the dataset, and then dragged a fresh copy of the table adapter from the server explorer and that fixed it
It is not clear why running a SELECT statement should involve enabling constraints. I don't know C# or related technologies, but I do know Informix database. There is something odd going on with the system if your querying code is enabling (and presumably also disabling) constraints.
You should also avoid the old-fashioned, non-standard Informix OUTER join notation. Unless you are using an impossibly old version of Informix, you should be using the SQL-92 style of joins.
Your question seems to mention two outer joins, but you only show one in the example query. That, too, is a bit puzzling.
The joining conditions between '
e
' and the rest of the tables is:This is an unusual combination. Since we do not have the relevant subset of the schema with the relevant referential integrity constraints, it is hard to know whether this is correct or not, but it is a little unusual to join between 3 tables like that.
None of this is a definitive answer to you problem; however, it may provide some guidance.
Thank you for all the input made so far. I just wanna add on that while one may have successfully normalized DB, updated any schema changes to their application (e.g. to dataset) or so, there is also another cause: sql CARTESIAN product (when joining tables in queries).
The existence of a cartesian query result will cause duplicate records in the primary (or key first) table of two or more tables being joined. Even if you specify a "Where" clause in the SQL, a Cartesian may still occur if JOIN with secondary table for example contains the unequal join (useful when to get data from 2 or more UNrelated tables):
Solution for this: tables should be related.
Thanks. chagbert
This problem is usually caused by one of the following
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:
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
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
This error was also showing in my project. I tried all the proposed solutions posted here, but no luck at all because the problem had nothing to do with fields size, table key fields definition, constraints or the EnforceConstraints dataset variable.
In my case I also have a .xsd object which I put there during the project design time (the Data Access Layer). As you drag your database table objects into the Dataset visual item, it reads each table definition from the underlying database and copies the constraints into the Dataset object exactly as you defined them when you created the tables in your database (SQL Server 2008 R2 in my case). This means that every table column created with the constraint of "not null" or "foreign key" must also be present in the result of your SQL statement or stored procedure.
After I included all the key columns and the columns defined as "not null" into my queries the problem disappeared completely.
I resolved this problem by opening the .xsd file with an XML reader and deleting a constraint placed on one of my views. For whatever reason when I added the view to the data it added a primary key constraint to one of the columns when there shouldn't have been one.
The other way is to open the .xsd file normally, look at the table/view causing the issue and delete any keys (right click column, select
delete key
) that should not be there.