Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Crystal Reports 2008 and ASP.NET Web Application Deployment - Tipps

Hello all,



The last few days I spent a lot of time trying to integrate a Crystal Report into an ASP.NET Web Application. In this post, I want to pass on some tips and I try to describe how I've achieved it finally to get this thing up and running


================

1. Prerequisites

================


Developer machine:

- Windows 2003 Server with IIS 6

- Visual Studio 2008 Standard Edition

- Crystal Reports 2008 SP2 installed (Full Product Install)

- Crystal Reports 2008 SP2 Runtime installed

- .NET Framework 3.5 SP1 installedv


Deployment machine:

- Windows Server 2008 with IIS 7

- Crystal Reports 2008 SP2 Runtime installed

- .NET Framework 3.5 SP1 installed


As you can see, my developer environment doesn't exactly match my target machine. I think it doesn't matter as long as you're using the same Crystal Report Runtime Version.


===================

2. Steps to Success

===================


Step 1: Create your Report

-

-




Use Crystal Reports Designer 2008 SP2 to generate your Report. Save it as RPT-File.


Step 2: Integrate ReportViewer Control into ASPX-Page

-

-




Open your desired ASPX-File and place the CrystalReportViewer Control on your page.



Here's my code for the CrystalReportViewer control:

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />


I had to make sure, that the following Assemblies were included in my web project:



- CrystalDecisions.Shared

- CrystalDecisions.Web




The Code-Behind file of my aspx-page looks like this:

    public partial class ShowReport : System.Web.UI.Page<br>
    {<br>
        protected void Page_Init(object sender, EventArgs e)<br>
        {<br>
            ConfigureCrystalReports();<br>
        }<br>
<br><br>
        private void ConfigureCrystalReports()<br>
        {<br>
            string ReportPath = "";<br>
            
            switch (Request.QueryString["id"])<br>
            {<br>
                case "1": ReportPath = Server.MapPath("MyReport1.rpt"); break;<br>
                case "2": ReportPath = Server.MapPath("MyReport2.rpt"); break;<br>
            }<br>
<br><br>
            ConnectionInfo connectionInfo = new ConnectionInfo();<br><br>

            connectionInfo.ServerName = "<your server name here>";        // Host name of database server<br>
            connectionInfo.DatabaseName = "<your database name here>";    // Database name<br>
            connectionInfo.UserID = "<your username here>";               // Username to login into database<br>
            connectionInfo.Password = "<your password here>";             // Password to login into database<br>
            CrystalReportViewer1.ReportSource = ReportPath;<br>
            SetDBLogonForReport(connectionInfo);<br>
        }<br>
<br><br>
        private void SetDBLogonForReport(ConnectionInfo connectionInfo)<br>
        {<br>
            TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;<br>
            foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)<br>
            {<br>
                tableLogOnInfo.ConnectionInfo = connectionInfo;<br>
            }<br>
        }<br>
    }<br>


As you can see, this source reads the id-parameter from the page request variable and then decides which report to load. This code assumes, that your rpt-files are placed in the same location as the aspx-page above. Server.MapPath then maps the website location to an absolute file system location. This is later passed to the viewer control which finally opens the file and renders it.


The code you see above is recommended by the crystal reports people (and is somewhere placed in one of their guides - app developer guide or api guide, I think).


Step 3: Configure IIS

-

-




When you install the Crystal Reports Runtime, you will notice, that a new directory has been created in your C:inetpubwwwrootaspnet_clientsystem_web2_0_50727 directory. This is the code which the CrystalReportViewer control needs in order to properly display the parameter input form and the rendered report.


I had to create a new virtual directory in my app which points to the aspnet_client folder. This is my setup of the virtual directory:


Virtual directory name: aspnet_client

Points to: C:inetpubwwwrootaspnet_client


The structure of your web app including aspnet_client virtual directory has to look like this after setup:

/MyWebApplication<br>
    /bin<br>
    /aspnet_client  --> this is the virtual directory!<br>
    Default.aspx<br>
   Web.config<br>


I also had to remove the web.config file inside the crystalreportviewers12 directory to get my app up and running. I don't know what the purpose of this web config file is. I'm currently investigating it as I've nothing found on the forums here. I would really appreciate it if anyone could point me to another forum thread regarding this topic.



Right, I hope I haven't forgotten anything to mention. Should one have questions I'm glad to help. Just let me know.


Step 4: Deploy your App

-

-




After that, I've deployed the app using the Publish.. function. You have to make sure, that you copy your reports to the same location as your aspx-page after deploying. Unfortunately I haven't worked out a better way to deploy the reports. But maybe anyone can help me here too?


Thank you.

André

Former Member
Not what you were looking for? View more on this topic or Ask a question