Showing posts with label VWD. Show all posts
Showing posts with label VWD. Show all posts

Friday, 7 April 2017

ASP.NET SQL Server: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

In an ASP.NET / SQL-Server web app I hit this error in a web form after modifying a the query of a TableAdapter in a .xsd file using VWD:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
The underlying SQL Query was a fairly simple UNION ALL query looking for a value (in this case an email address) across several different tables. I had two new tables to search in, so I simply added two more UNION ALL sections to the query for these new tables.

Then I hit the above error. There were some slight differences to the column definitions between the new tables and the existing ones. I tried all sorts of things including CASTing variables and checking for NULLs, all to no avail. Eventually I twigged that it was hanging on to something in the .xsd file behind the scenes.

Solution: Copy the SQL from the table adapter, delete the table adapter, then re-create it and paste in the old SQL. Runs perfectly. (Well, it did after I had two goes at getting the table adapter name exactly the same as before!)

Oh the joys...!

Friday, 9 March 2012

VWD + ASP.NET + MySql + parameterized queries

As you'll know, MS-SQL-Server uses parameter names beginning with '@' in parameterized queries, whilst MySql uses a single '?' for each parameter.

Whilst struggling to get Visual Web Designer 2010 Express to recognise parameterized MySql queries, I hit on the following technique:

VWD 2010 Express + MySql Connector/Net

Anyone trying to link the MySql Connector/Net connector into an ASP.NET site using the (free) Visual Web Developer 2010 Express?

Well, I found out the hard way that it is not compatible. Installed the Connector/ODBC version, and I was able to connect successfully.

From dev.mysql.com: "Note that MySQL Connector/Net does not currently support Express versions of Microsoft products, including Microsoft Visual Web Developer."