We help IT Professionals succeed at work.

How to close  crystal report object? PLS HELP

AnnaJames77
AnnaJames77 used Ask the Experts™
on
Public Sub ShowReport(ByVal OrderNo)
        Try
            Dim theReport As New ReportDocument
            theReport.FileName = "C:\Results.rpt"
            theReport.SetParameterValue("@orderno", OrderNo)
            CrystalReportViewer1.ReportSource = theReport
            CrystalReportViewer1.Visible = True
        Catch ex As Exception
            MsgBox("An Error Occurred: " & ex.ToString())      
        End Try

I call the above code from another form as Rep.show(parameters) in a loop;
ie
for loop
Rep.show(parameters)
end for

I want to know how should i close and dispose the report object ie, theReport.
As i get an error as below
"The maximum report processing jobs limit configured by your
system administrator has been reached.How I can Solve this
problem when i using crystal report to load from my
application."
in google its suggested to close the report object. But when i give the thereport.close and thereport.dispose it gives an error  like "Pure Virtual Function Call"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer cum AD Developer
Commented:
I'm not familiar with VB but in C# you do as:

private void Page_Unload(object sender, System.EventArgs e)
{
       if(theReport != null)
       {
             theReport.Close();
             theReport.Dispose();
       }
 }

Open in new window


Checkout for more @

1. http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=1205

2. http://forums.asp.net/t/1370381.aspx/1?crystal+reports+close+and+dispose
Vikram Singh SainiSoftware Engineer cum AD Developer

Commented:
Sorry! Didn't read your last paragraph. For that problem you can click http://geekswithblogs.net/technetbytes/archive/2007/07/17/114008.aspx
Most Valuable Expert 2012
Top Expert 2014

Commented:
Are you doing something else in the loop as well? If not, showing multiple reports in same viewer within a loop does not make sense. Are you printing the reports? If so then use the PrintToPrinter method directly without showing the report

http://devlibrary.businessobjects.com/businessobjectsxi/en/en/crystalreports_dotnet_sdk/crystalreports_net_doc/doc/crsdk_net_doc/html/crlrfreportdocumentclassprinttoprintermethodtopic.htm

Author

Commented:
yes code cruiser i am not using the crystal report. i do direct printing in the loop. just for checking i use the crystal report viewer. even if i give directly i get the above same error if there are more than 1 report to print in the loop. i need to know how should i close /dispose the report object after each print
Most Valuable Expert 2012
Top Expert 2014

Commented:
Try setting the reportobject to Nothing. Then every so often, call the GC.Collect()

Example:

Dim Temp As Integer
For i as integer ...
   'ShowReport
   Temp += 1
   ReportDoc = Nothing
   If Temp = 10 Then
      GC.Collect()
      Temp = 0
   End If
Next
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
How many reports are you trying to open?
There are limits set in Crystal to the number of open connections.  That number is affected by how the report is built as I believe subreports count as a connection.

What other code are you using since the subreport ending should close the opened report document and you haven't really done anything with it other than show it in the viewer.

mlmcc

Author

Commented:
it doesnt have any subreports. There can be more than 30 reports to print in the loop. its chosen by the user. I want to know where should i call this dispose and close method. Is it in the calling form or on the report printing form. If i dispose it in the report printing form and selects only one value, ie the loop executes only once then there isnt any error. But if selects more than one, then i get  error : object not set to an instance of the object.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Show us the code from the form that is printing and the code that is calling it.
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Author

Commented:
i used the
theReport.Close();
theReport.Dispose();
to solve the issue
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Asker has provided the answer.

The answer is basically the code provide by vs00saini in the first comment

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_27243619.html?cid=1572#a36327679 

Please change recommendation to

Accepted Answer - vs00saini  http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_27243619.html?cid=1572#a36327679

mlmcc
CV

Commented:
All,
 
Following an 'Objection' by mlmcc (at http://www.experts-exchange.com/Q_27293076.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
_alias99
Community Support Moderator