Custom Report Generator working Inconsistently

Posted on 2007-08-08
Last Modified: 2008-01-09
I have created a generic crystal report viewer in  One page has a list of reports.  You click on the report, then a dynamic list of parameters for that query show up.  Once their items are selected, they click the "run report" button.

This button pulls the data (datatable) from the database, and gets the path for the report,puts the data into session variables and then opens the report viewer, which looks for the session variables.

Sometimes this works, sometimes it does not.  Some times says "File does not exist", but it just ran successfully, and will run again right after the failure.  Other messages I get are "unable to cast object of type 'System.String' to type 'System.Data.Datatable'

Here is the code that I use to open and send the data.
Session("ReportDT") = dtReportData
            Session("ReportPath") = strPathAll

            Dim jscript As String = "<script>""ReportViewer.aspx"","""", ""toolbar=no,resizable=1,menubar=no,scrollbars=1"")</script>"
            Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "Report", jscript)

Here is the code that  is used in the report viewer screen:
'Get Session Variable information
            If Not Page.IsPostBack Then
                'Add to local computer
                dt = CType(Session("ReportDT"), DataTable)
                strPath = Session("ReportPath")

                'Put into the viewstate
                ViewState.Add("ReportDT", dt)
                ViewState.Add("ReportPath", strPath)

                'Empty the session state
                Session("ReportDT") = ""
                Session("ReportPath") = ""
                dt = ViewState("ReportDT")
                strPath = ViewState("ReportPath")
            End If
            'Create report
            oRpt = New ReportDocument

            'TODO: Error check for bad path
            If System.IO.File.Exists(strPath) Then
                oRpt.Load(strPath) 'Session("ReportPath"))

                MyViewer.PrintMode = CrystalDecisions.Web.PrintMode.Pdf ' CrystalDecisions.Web.PrintMode.ActiveX

                MyViewer.ReportSource = oRpt
                Err.Raise(513, , "File Does not exist")
            End If
Question by:smcdrc
    LVL 2

    Author Comment

    Or is there a better way to pass the parameters that is consistent/less error prone.
    LVL 42

    Expert Comment

    Sounds to me like you're losing the session values - that would account for both of the errors that you see.  Could be a timeout issue on your server (is the user looking at one report long enough to timeout the session before they view another one?).  Could also be network problems as well.

    You might want to modify your code to verify that ReportDT and ReportPath have a value in the ViewState and throw an exception if they don't.
    LVL 2

    Author Comment

    Is there  a better way to transfer the data between the screens.  I looked into sending it using "context" and server.transfer.  But I want it to open into a new window each time so that they can compare reports next to each other.

    LVL 42

    Expert Comment

    You can use server.transfer and send the info in querystring.  You can post the content to another page (lots of discussions on that - here's one: ).  There are many ways to handle it - I would add the code I suggested first and confirm that is the problem before you do anything else...
    LVL 2

    Author Comment

    I am droping the session values somehow.  The Session timeout is set to 20 minutes.  From what I have been reading, the sesison aspect of .net is very buggy.  I will look into posting to viewer page.

    I do not think the querystring would work because the datatables can be quite large.  I guess I could send the stored procedure name/parameters to the viewer and allow it to do the query.
    LVL 42

    Accepted Solution

    >>> I guess I could send the stored procedure name/parameters to the viewer and allow it to do the query.

    That's the approach I'd take so you don't have to pass datatables around.  Just send the info needed to create the tables to your viewer page.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now