Crystal and XML DataSets

I've had some more Crystal Reports hatred today. I had to revisit an old program to add some reports to it. Due to our crappy development process and the cheapness of my boss, I did it in .NET 2.0, but with .NET 1.0 bundled Crystal Reports. Basically, I ended up with my main .NET 2.0 program and a separate .NET 1.0 executable to do the reports. I just shell out to the report program and pass it paths to the Crystal Report file and an ADO.NET XML file for the data. It's not pretty, but it could be a lot worse.

Given this setup, I thought adding a couple of simple reports would be a piece of cake. The reports were basically just table listings - putting "select * from foo;" into a user-friendly format. I figured it would take me an hour tops. Little did I know....

My problem was simply that the report didn't work. I had my report file and my ADO.NET dataset, I ran the report program, and the Crystal Report preview control threw up a "query engine error" message. If you're not familiar with Crystal, that pretty much just means that something bad happened when Crystal was trying to populate the report. It could be a problem connecting to the database, it could be a malformed query, or it could be that the alignment of the planets has raised evil spirits that are interfering with your computer. Nobody can say for sure and Crystal doesn't really give you any easy way to figure it out.

After some testing, it turned out that the problem was the xml:space attribute. Apparently the ADO.NET DataSet.WriteXML() method adds xml:space="preserve" to fields that contain only whitespace. However, Crystal Reports for Visual Studio .NET 2002 really doesn't like this and bombs out with a query engine error when it sees this. Just having whitespace-only fields is no problem, it's only when this attribute is present that Crystal freaks out.

So now at least I know what the problem is. The immediate fix is easy - just get rid of the spaces in the database and keep the user from putting in more. It still galls me a little that that's necessary, though. I would have thought Crystal would just ignore unrecognized attributes. But at this point, I shouldn't be surprised by the crappy things I find in Crystal.

You can reply to this entry by leaving a comment below. You can send TrackBack pings to this URL. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.