To view a Crystal Report on a .NET page, all you have to do is use the included Crystal Report Viewer, which is basically a .NET control. You can save your Crystal Report as a .RPT file, include it in your .NET web project, and a proxy class (of type CrystalDecisions.CrystalReports.Engine.ReportClass) is auto-generated. For example, if your file is located at /MyReport.rpt, a proxy class called MyReport is auto-generated in /MyReport.cs. The Crystal Report Viewer takes this proxy class as its ReportDataSource, and takes as its datasource any bindable data structure (DataTable, DataSet, DataReader, etc.) that matches the schema of the report itself. So if you used a certain database view to generate your report, your Crystal Report Viewer datasource must be selected from this same view.
Here is some sample C# code:
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;First Problem: Permissions
protected MyReport report = new MyReport();
...
DataTable dt = SelectFromDatabaseView(arguments);
CrystalReportViewer1.SetDataSource(dt);
CrystalReportViewer1.ReportSource = report;
The code worked great so we were ready to push it to another server (the test server). But when I tested the code on my own machine, it didn't work. Here's the error I got when I tried to set the DataSource:
"Access to the path \"C:\\DOCUME~1\\DWBUTL~1\\ASPNET\\LOCALS~1\\Temp\\temp_66cf7594-54e8-43ef-959c-8b47b98500ac.rpt\" is denied."
Apparently Crystal Reports was trying to write to some temporary directory it didn't have access to. My IIS instance was set up to impersonate, which means IIS runs as a specific user rather than the default Internet Guest Account (IUSR_
Of course, if I had set up impersonation properly in the first place, I may not have had this problem. (Detailed instructions for setting up permissions for the impersonation account are located at MSDN.) I got lazy and didn't follow the full instructions, because everything was working fine.
Strangely enough though, Crystal Reports doesn't seem to use the same directories that IIS is supposed to use. On the test server, Crystal Reports used the C:\Windows\Temp folder. On my own machine, it used C:\Documents and Settings\
Second Problem: Missing Virtual Directory
After I fixed the first problem, the report displayed properly. But then we had a second problem: all the images were broken. Viewing the location of the images, I noticed they were located on http://
The only way around this, it appears, is to copy the virtual directory crystalreportviewers115 from the Default Web Site to whatever web site you need it in. The geniuses at Business Objects didn't give an option which web site to install into.
This might be easy or hard, depending on your situation. If you have IIS 6, you can export the virtual directory configuration to an xml file, and then create a new virtual directory in another web site from the same xml file. If you have IIS 5, you'll probably need to copy things manually. If your virtual directory is simply gone, you'll have to create it from scratch.
Conclusion: This is so messed up that it makes babies cry and turn to stone.
No comments:
Post a Comment