Inconsistent "Failed to enable constraints" error
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.