Wednesday, April 22, 2009

Upgrading Crystal Reports Files from VS2005 to VS2008

I just upgraded a fairly large project from Visual Studio 2005 to 2008. Everything went fairly smoothly but I did encounter hundreds of errors when I got around to upgrading the Crystal Reports data files.

In VS2005 I have a pair of files for each report:
  • ReportName.rpt
  • ReportName.xsd
where "ReportName" changes accordingly.

In VS2008, when you bring an XSD file into a project it creates 3 other files:
  • ReportName.Designer.cs
  • ReportName.xsc
  • ReportName.xss
I didn't know the purpose of this trio but assumed they were necessary in VS2008.

In point of fact, all the conflicts occured within the ".Designer.cs" files. There are global variables in each one that cause repeat definitions of the same variables, which is not allowed.

So I did a little research and came across this blog entry. I ended up following just the first part, which was to delete the ".Designer.cs" and ".xss" files. Plus, because all the ".xsc" files were empty, I deleted them too.

Lo and behold, I rebuilt the solution but these excess files were never recreated. More importantly, the reports worked perfectly once again!



Update: One problem I've discovered with the above procedure is that you still end up with one warning message per report like this:

The custom tool 'MSDataSetGenerator' failed while processing the file 'Reports\Templates\MTHOBRK3.xsd'.

The application still runs but I don't like any such warning messages to be present. After a little trial & error I found this to be the ultimate solution:
  1. Delete the .xsc & .xss files only.
  2. Replace the entire contents of each .Designer.cs file with the following:
#pragma warning disable 1591

namespace Website.Reports.Templates
{
public partial class NewDataSet
{
}
}

#pragma warning restore 1591

2 comments:

  1. I am using visual studio 2008 to develop a web application where I am using the crystal reports. I have placed the viewer in my default.aspx page. I am using datasets which hit the sql server 2005 tables. Right now the application runs off of my local host, is not published to a server. I have following questions.

    1. Do I need to have crystal reports installed in the clients' machine also for them to view the report or it opens as an html page?

    2. Right now, I can query and view my results in the crystal report viewer. It just works fine. I am trying to use the default crystal report viewer toolbar to export, print and navigate to different pages of report. So I can view the report, it just works so fine until I press one of the default buttons in the toolbar. For eg, on the report, when I get the results, if I click on Export button of the toolbar, it pops up the window for export but then the aspx page where I have the viewer immediately comes out with error.."Database logon failed.Cordus_Opolus. ..C:\local settings\ user\temp\.....reportname.rpt. Cannot set the object reference to its instance...unable to log in." Why does this happen? When I can view the report fine, that means I am able to login successfully and display the result in the viewer but why does it error out when I try to export or print or go to next page or previous page? Could you please share your ideas\experiences on this issue?

    ReplyDelete
  2. You only need to have the necessary CR DLLs installed on the server, not on the client machines. Also, my understanding is that if the users don't need to design any reports on their own then the license that comes with VS2008 is sufficient to deploy the CR reports at no extra cost.

    I've never used the CR Viewer so have no advice for you, sorry.

    ReplyDelete