Wednesday, 7 March 2012

Confusing data error

I have a gridview that is very basic and list name, address, ......, and a URL.

If I have this url in the database I have no problemhttp://www.lubbockisd.org/earlychildhood/

yet when I place this URLhttp://www.lubbockisd.org/erlychildhood/stubbs.htm

It triggers this error on my localhost server and my production server.

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

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I've made changes to datatypes with no success, made sure my length of data type was set long enough with no success.

Which datatype is best for a URL in sql express?

Any ideas why this happens with such a minor change?

Thanks

Tony


Hi. Tha dataTable you are using as Datasource for the gridview has a unique constraint in the column you are changing tha data, or the column is defined as primary key... and you are attempting to insert a data that is not unique|||

You may have already done all this but I just want to make sure that that URL is not already present in the database. Other than that, what are the constraints on your fields. Does the URL field accepts only unique values.

bullpit

|||

Thanks for replying so quickly,

That is what is confusing me so much, I don't have any constraints on this field, nor is it a unique or identifier field.

Tony

|||

Hi Tony,

Is there any other table that reference this field in the DataSet?

|||

Nope, this is the only page that uses this particular table...http://www.tonyhager.com/schools/prek.aspx

TH

|||

Hi,

Please check each column that you have constraints on this table. If it has a unique constraint, make sure it is not violated with a duplicated value.

A VarChar data type will be suitable to store URLs.

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

|||

As stated previously, I have no constraints in this table. You can see that I have the URL duplicated on the page in question in the table with all three of the PreK schools listed. I have 5 pages that use this data table and none of the other pages trigger the error even when I have the URL that does trigger the error on the PreK page the other pages work fine. It only happens when I add the page name to the one URL. The default page ishttp://www.tonyhager.com/schools/

Thanks again,

TH

|||

Hi,

To troubleshoot on this issue, if you're using a DataSet to store the values, I suggest you use WriteXml("filename.xml", XmlWriteMode.WriteSchema) to write all the data and schema out to an xml file.

Analysis on this file will reveal where the constraint error is. If you're having problem, you can paste it here together with the new data you're inserting to this DataSet, and I will try to check this for you.

|||try checking your XML schema designer page and see if any of your fields have theNullValue property set to "(Throw exception)". If so, then try changing it to null.|||

Would I even have a XML schema page if I am using a sql express database? Where do I look for this page?

|||the XSD schema is generated if you "drag and drop" your tables. It creates strongly typed objects through which you can manage your scheme via the designer's interface.

if a schema has been generated it is normally generated under your "App_Code" folder and the name ends in "XSD". If you don't have a schema then you may want to consider this approach for creating strongly typed datasets in the future. It is much quicker and less error prone.|||Every field had it set to "throw exception" is that a default setting? So I should change each string field to read null?|||

only change the "offending" fields to null (unless you don't mind your other fields accepting null values as well).

the dataset schema acts as a second 'safety mechanism' to catch data-type mismatches, differences in column names, null values etc. It is a good thing but it can cause confusion sometimes because it adds an extra layer of complexity

No comments:

Post a Comment