?
Solved

Custom Report Generator working Inconsistently

Posted on 2007-08-08
6
Medium Priority
?
402 Views
Last Modified: 2008-01-09
I have created a generic crystal report viewer in vb.net.  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>window.open(""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") = ""
            Else
                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"))
                oRpt.SetDataSource(dt)

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

                MyViewer.ReportSource = oRpt
                MyViewer.DataBind()
                MyViewer.RefreshReport()
            Else
                Err.Raise(513, , "File Does not exist")
            End If
0
Comment
Question by:smcdrc
  • 3
  • 3
6 Comments
 
LVL 2

Author Comment

by:smcdrc
ID: 19654521
Or is there a better way to pass the parameters that is consistent/less error prone.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 19654728
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.
0
 
LVL 2

Author Comment

by:smcdrc
ID: 19654763
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.

Thanks,
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 42

Expert Comment

by:frodoman
ID: 19654839
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: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21957263.html ).  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...
0
 
LVL 2

Author Comment

by:smcdrc
ID: 19655231
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.
0
 
LVL 42

Accepted Solution

by:
frodoman earned 2000 total points
ID: 19655416
>>> 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.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

588 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