Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Inconsistent "Failed to enable constraints" error

Inconsistent "Failed to enable constraints" error

Scheduled Pinned Locked Moved ASP.NET
databasehelpsql-serversysadmin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johan Hakkesteegt
    wrote on last edited by
    #1

    Hi, I have a datatable with tableadapter, and two parameterized queries. The queries are quite straightforward, the parameter is the product EAN code, or the product number, and it returns a single row with product information (description, available stock, etc). They both work perfectly, except when I run them for a certain product. So I copy the query to sql server management studio, and they run fine, also for the offending products. Through some googling I found that it is a common problem occuring to many, having (alternating) to do with EnforceConstraints, or field lengths, or data type mismatch, or AllowDBNull, with one common denominator: the query does not run at all... But my query does run, just not for a couple of products. So I compare the queried data of a "good" product with that of a "bad" one, and lo an behold, the data is the same. No missing data, no differences in length, or data type, or anything. Anyone who can shed some light on this, will be my hero. :-\ :rose: Cheers, Johan

    My advice is free, and you may get what you paid for.

    E 1 Reply Last reply
    0
    • J Johan Hakkesteegt

      Hi, I have a datatable with tableadapter, and two parameterized queries. The queries are quite straightforward, the parameter is the product EAN code, or the product number, and it returns a single row with product information (description, available stock, etc). They both work perfectly, except when I run them for a certain product. So I copy the query to sql server management studio, and they run fine, also for the offending products. Through some googling I found that it is a common problem occuring to many, having (alternating) to do with EnforceConstraints, or field lengths, or data type mismatch, or AllowDBNull, with one common denominator: the query does not run at all... But my query does run, just not for a couple of products. So I compare the queried data of a "good" product with that of a "bad" one, and lo an behold, the data is the same. No missing data, no differences in length, or data type, or anything. Anyone who can shed some light on this, will be my hero. :-\ :rose: Cheers, Johan

      My advice is free, and you may get what you paid for.

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      When the data has been verified manually, repeatedly, this error is usually the result of a constraint being accidentally assigned to the wrong column. Ie, instead of Customer.id = order.CustomerId you may have Customer.Id = order.ProductId. The constraints work in most cases for populated databases, however, fail at seemingly odd interval with no other explanation.

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

      J 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        When the data has been verified manually, repeatedly, this error is usually the result of a constraint being accidentally assigned to the wrong column. Ie, instead of Customer.id = order.CustomerId you may have Customer.Id = order.ProductId. The constraints work in most cases for populated databases, however, fail at seemingly odd interval with no other explanation.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

        J Offline
        J Offline
        Johan Hakkesteegt
        wrote on last edited by
        #3

        Thanks Ray, at the very least I am glad to hear I am not just crazy.

        Ennis Ray Lynch, Jr. wrote:

        fail at seemingly odd intervals

        In my case the query consistently fails when I run it with one product number and succeeds when I run it with another. When I run the page (query) in quick succession (good one, bad one, good one, bad one, etc) it consistently succeeds and fails (perhaps the title of this post wasn't chosen too well...) Is this behavior what you meant, or would it occur completely at random? If you have had to deal with this problem as well, can you please suggest a work around or something ? Cheers, Johan

        My advice is free, and you may get what you paid for.

        E 1 Reply Last reply
        0
        • J Johan Hakkesteegt

          Thanks Ray, at the very least I am glad to hear I am not just crazy.

          Ennis Ray Lynch, Jr. wrote:

          fail at seemingly odd intervals

          In my case the query consistently fails when I run it with one product number and succeeds when I run it with another. When I run the page (query) in quick succession (good one, bad one, good one, bad one, etc) it consistently succeeds and fails (perhaps the title of this post wasn't chosen too well...) Is this behavior what you meant, or would it occur completely at random? If you have had to deal with this problem as well, can you please suggest a work around or something ? Cheers, Johan

          My advice is free, and you may get what you paid for.

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          You would have to post the schema's and the queries for the tables involved for someone to rule out database code. You mention that you are using a Table Adapter, are you using generated code or strongly typed DataTables? If so your code may not reflect your current database. For a quick test, in your ASPX code that is failing, randomly, replace your data access with straight data readers and no DataSet related objects and see if the error goes away. You have to slowly prove each piece of the code before you can identify which piece is wrong. As for random, I seriously doubt the error is random, they never are. It is just the underlying cause has not yet been identified.

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

          J 1 Reply Last reply
          0
          • E Ennis Ray Lynch Jr

            You would have to post the schema's and the queries for the tables involved for someone to rule out database code. You mention that you are using a Table Adapter, are you using generated code or strongly typed DataTables? If so your code may not reflect your current database. For a quick test, in your ASPX code that is failing, randomly, replace your data access with straight data readers and no DataSet related objects and see if the error goes away. You have to slowly prove each piece of the code before you can identify which piece is wrong. As for random, I seriously doubt the error is random, they never are. It is just the underlying cause has not yet been identified.

            Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

            J Offline
            J Offline
            Johan Hakkesteegt
            wrote on last edited by
            #5

            Unfortunately the table adapter is generated, so its a bit tricky to control, but I am going to take your advice and test my code until I find the offending bit. I am also leaning towards your suggestion that the schema does not reflect the database, so I will first recreate the whole table adapter from scratch, to have it match up again. Who knows, that may already do the trick. Thanks Ray, I appreciate your help.

            My advice is free, and you may get what you paid for.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups