March 2008 Archives
Book Review: ASP.NET 3.5 Unleashed by Stephen Walther
Posted on March 31, 2008 | 2 Comments | No TrackBacks
A while back I posted a review of Stephen Walther's ASP.NET 2.0 Unleashed. It's a fantastic book that I've used more times than I can count. The release of the .NET 3.5 framework means there are lots of new things to learn. Thankfully, Mr. Walther has released an amazing follow up-book titled ASP.NET 3.5 Unleashed.
At 1890 pages this book has just about everything you need to know to start building complex ASP.NET applications. While the book assumes that you have some familiarity with using ASP.NET the first few chapters are still devoted to the basics. I encourage everyone to read them, even the experts. There are many tips and tricks in the book so you may learn something new or pick up on something you'd long forgotten. Did you know the asp:Literal control has a build in Mode property that can be set to HTML encode it's content? I'd honestly forgotten about that and had been doing my encoding on the back-end.
This book provides an in-depth look at just about all of the core ASP.NET features building on many of the techniques we used in 2.0. For the new features specific to ASP.NET 3.5 , Walther devotes an entire chapter to the new ListView and DataPager controls. These controls can be thought of as a GridView or Repeater on steroids. There's also a chapter on data access with LINQ to SQL and a 3-chapter section devoted to working with AJAX.NET and the AJAX Control Toolkit.
There are many books out there that focus on the "how" but what I like most about Mr. Walther's books is that he devotes a great deal of time to the "why". For example, the book explains how to use the SqlDataSource control but then also explains why you'll want to avoid it for most complex applications and use the ObjectDatasourceControl instead. With this book you'll not only learn how to get things done, you'll learn how to get things done right. For that reason it's an invaluable resource for your library. Every ASP.NET developer should have this book on his/her shelf.
Note: While the code samples in the previous 1.1 and 2.0 Unleashed books were written in VB.NET, this new 3.5 book has them written in C#. Walther cites the fact that there are now more C# developers than there are VB.NET developers as the reason for the switch. I would've liked to have seen two different versions of the book but all code samples are also provided in VB on the included CD-ROM so everyone can easily follow along.
ASP.NET "Failed to enable constraints" dataTable error
Posted on March 8, 2008 | Leave a Comment | No TrackBacks
I'm building an ASP.NET application this weekend and ran into the following error.
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
The error message itself is somewhat vague and it took me a little while to troubleshoot it so I thought I'd post my solution here. There are many reasons you could get this error, the most obvious being that you may have data in your database that contains a null value or that violates a foreign-key constraint.
I spent a while checking my database and everything seemed to be in order. There were no null values where there shouldn't be, my relationships were setup properly, and I'd double-checked that I wasn't enforcing foreign-key constraints.
After wracking my brain for a while, I started Googling and found some suggestions in a few different .NET forums which helped fix the problem. It turns out that during my data-importing I'd decided to change a field in one of my tables from VARCHAR(50) to VARCHAR(100) because some of the data was larger than I'd originally expected. However, I'd neglected to update the MaxLength property of the same field in my DataSet file. This disparity is what caused the problem. Updating the MaxLength property to 100 instantly fixed the issue.
So this error message can be somewhat misleading. If you find yourself faced with this error and you've checked all the things that the error message suggests and you're still having problems, check to see that the sizes of your database fields match the sizes in your dataset.

