Failed to enable constraints

Discussion in 'ASP .Net Web Controls' started by cs_in_va, Feb 19, 2008.

  1. cs_in_va

    cs_in_va Guest

    I get the following error when trying to access a page (prodcuts.aspx)
    with a single drop down list box bound to a objectdata source linked
    to my categoryBLL,.vb file. Here is what I have.

    Table Categories with CategoryId and CategoryName.

    My DAL for this is very simple again:

    SELECT CategoryID, CategoryName, Image
    FROM Categories

    Have a categoryBLL with the following code:

    Imports ADAHSTableAdapters

    <System.ComponentModel.DataObject()> _
    Public Class CategoriesBLL
    Private _categoriesAdapter As CategoriesTableAdapter = Nothing
    Protected ReadOnly Property Adapter() As CategoriesTableAdapter
    Get
    If _categoriesAdapter Is Nothing Then
    _categoriesAdapter = New CategoriesTableAdapter()
    End If

    Return _categoriesAdapter (error line)
    End Get
    End Property


    <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
    True)> _
    Public Function GetCategories() As ADAHS.CategoriesDataTable
    Return Adapter.GetCategories()
    End Function

    <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
    False)> _


    Public Function GetCategoryByCategoryID(ByVal categoryID As
    Integer) As ADAHS.CategoriesDataTable
    Return Adapter.GetCategoriesByCategoryID(categoryID)
    End Function
    End Class


    Error Message on aspx page:

    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.

    Source Error:


    Line 2931: Me.Adapter.SelectCommand =
    Me.CommandCollection(0)
    Line 2932: Dim dataTable As ADAHS.CategoriesDataTable = New
    ADAHS.CategoriesDataTable
    Line 2933: Me.Adapter.Fill(dataTable)
    Line 2934: Return dataTable
    Line 2935: End Function


    Stack Trace:


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

    .....More stuff,

    CategoriesBLL.GetCategories() in C:\DNN_Web_Dev\ADAHS\App_Code\BLL
    \CategoriesBLL.vb:18


    Now when I preview the data in my tableadapter (categoriesDataTable) I
    have no problem everything is displayed properly, but when I try and
    link the Drop Down List to it I get the same error. I have tried not
    using the BLL file and get the same error. Line 18 is "Return
    _categoriesAdapter"

    So where am I going wrong?

    Thanks
     
    cs_in_va, Feb 19, 2008
    #1
    1. Advertising

  2. cs_in_va

    Mr. Arnold Guest

    "cs_in_va" <> wrote in message
    news:...

    <snipped>

    You have foreign key value that's in a table that's either a null value or
    the value is not null but is pointing to key on a record in the foreign
    table that's not there.
     
    Mr. Arnold, Feb 19, 2008
    #2
    1. Advertising

  3. cs_in_va

    cs_in_va Guest

    On Feb 18, 9:57 pm, "Mr. Arnold" <MR. > wrote:
    > "cs_in_va" <> wrote in message
    >
    > news:...
    >
    > <snipped>
    >
    > You have foreign key value that's in a table that's either a null value or
    > the value is not null but is pointing to key on a record in the foreign
    > table that's not there.


    Why would it work if I executed the query from the table adapter if
    that were the case?

    The table is fully populated. I have even taken away any FK's
    responding to the categories table and still get the same issue.
     
    cs_in_va, Feb 19, 2008
    #3
  4. cs_in_va

    Mr. Arnold Guest

    "cs_in_va" <> wrote in message
    news:...
    > On Feb 18, 9:57 pm, "Mr. Arnold" <MR. > wrote:
    >> "cs_in_va" <> wrote in message
    >>
    >> news:...
    >>
    >> <snipped>
    >>
    >> You have foreign key value that's in a table that's either a null value
    >> or
    >> the value is not null but is pointing to key on a record in the foreign
    >> table that's not there.

    >
    > Why would it work if I executed the query from the table adapter if
    > that were the case?


    I don't know.

    >
    > The table is fully populated. I have even taken away any FK's
    > responding to the categories table and still get the same issue.
    >


    I am just telling you what the message means. You got null data or invalid
    data in a field pointing to a table that has a foreign constraint applied.

    ---------

    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.
     
    Mr. Arnold, Feb 19, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page