on 05-11-2009 2:39 PM
I am using crystal reports that come with visual studio 2008 and i also tested with visual studio 2005.
I have a report and i can view any number of reports but when i export the report as pdf or any other format.The next report fails. Is there a solution to address this problem . I am just using the crystal reports viewer to show the report.
This is a windows application hence i am using the reportviewer that comes with the visual studio to show the report and using the menubar button to export the report.
The error i get is simple "LOAD REPORT FAILED"
Any Help???????????
Hi,
Please make sure that you are loading the report in report document object properly. One thing is to check if the path of the report is proper.
Also make sure that you are redefining the reportdocument object before selecting the report. Is it possible to share your code?
Here is the code that works fine at my end:
ReportDocument rdoc = new ReportDocument();
rdoc.Load("C:
Temp
Report.rpt");
CrystalReportViewer1.ReportSource = rdoc;
Regards,
AG.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks AG .
My Problem is not loading the report for the first time . I can view any number of reports by changing the search criteria. But If i use the export icon in crystal report viewer to save it into the any available format. It is fine till then.
If i cange the search criteria again and when i try to view the report again then it fails to load.
Do you know y ??
No sure what is going wrong at your end. Here is the code that I used and it worked fine for multiple exporting.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows;
using CrystalDecisions.Shared;
private void Form1_Load(object sender, EventArgs e)
{
ReportDocument rdoc = new ReportDocument();
rdoc.Load(@"C:\Program Files\Microsoft Visual Studio 9.0\Crystal Reports\Samples\En\Reports\General Business\Employee Profile.rpt");
crystalReportViewer1.ReportSource = rdoc;
}
try the same in a simple app then move to your project.
Regards,
AG.
Your code does not really show much - I don't think that is the full code as it applies to CR(?). Not sure why you dim all the database logon objects(?).
I would suggest downloading our sample apps from here:
https://smpdl.sap-ag.de/~sapidp/012002523100006252822008E/net_win_smpl.exe
Use the sample vbnet_win_simplepreview and see if you can duplicate the issue.
Also, specify what version of CR you are using.
What version of .NET you are using.
What SP for CR has been applied.
Ludek
Dim cr As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
cr.Load(pRptName)
'Get database connection info
With crConnectionInfo
.ServerName = My.Settings.ConnectionString.Split(";")(0).Split("=")(1)
.DatabaseName = My.Settings.ConnectionString.Split(";")(1).Split("=")(1)
.UserID = My.Settings.ConnectionString.Split(";")(3).Split("=")(1)
.Password = My.Settings.ConnectionString.Split(";")(4).Split("=")(1)
End With
'Set database connection for all tables in report
CrTables = cr.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
' Loop through each section and find report objects
Dim crReportobjects As ReportObjects, crSubReportobject As SubreportObject, subReportDocument As ReportDocument
Dim crDatabase As Database
Dim crSections As Sections = cr.ReportDefinition.Sections
For Each crSection As Section In crSections
crReportobjects = crSection.ReportObjects
For Each crReportobject As ReportObject In crReportobjects
If crReportobject.Kind = ReportObjectKind.SubreportObject Then
' If a subreport is found cast as subreportobject
crSubReportobject = CType(crReportobject, SubreportObject)
' Open the sub report
subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName)
crDatabase = subReportDocument.Database
CrTables = crDatabase.Tables
' Loop through each table in the sub report and set the connection info
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
End If
Next
Next
If Not chkSelectClient.Checked Then
'Show all invoices
cr.RecordSelectionFormula = "{Invoices.invoice_date} in {?StartDate} to {?EndDate} and {Subject_Names.primary_name} and {Clients.billing_cycle} = {?Filter_BillingCycle}"
Else
'Invoice Number report parameter
cr.SetParameterValue("Filter_InvoiceNumber", Me.cboInvoices.Text.Trim)
cr.RecordSelectionFormula = "{Subject_Names.primary_name} and {Invoices.invoice_number} = {?Filter_InvoiceNumber} and {Clients.billing_cycle} = {?Filter_BillingCycle}"
End If
'Set report parameters
cr.SetParameterValue("StartDate", Me.dtpStart.Value)
cr.SetParameterValue("EndDate", Me.dtpEnd.Value)
cr.SetParameterValue("Filter_BillingCycle", IIf(Me.optMonthly.Checked, "Monthly", "Weekly"))
'cr.SetParameterValue("location_id", Me.locationNameComboBox.SelectedValue cr.SetParameterValue("Billing_Contact", Billing_Contact.ToString())
'Show report
With CrystalReportViewer1
.ReportSource = cr
.Zoom(100)
.DisplayGroupTree = False
.Visible = True
.Refresh()
End With
This is the complete code for my report and i use it and i can view any number of reports before exporting.
I am using visual studio 2008 and crystal reports 10.5 that comes with the VS2008 and i have applied servicepack 1 .
If you need any more details let me know
Edited by: manojbavikati on May 13, 2009 4:24 PM
Righ, I don't think that came in quite right...(?). Repost ensuring the post is readable. Also, do try the sample app too.
If these suggestions are not of any help to you, consider obtaining a single phone support contract from here:
Ludek
Hello,
I think the problem is once you are finished with the report you need to close and dispose your report object. I copied your code into VB .NET and I think I have most of it but not sure.
Which Viewer are you using? In your references are you using CrystalDecisions.Windows.Forms or did you try using the crviewer.dll?
Dim cr As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo '
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
cr.Load(pRptName)
'Get database connection info
With crConnectionInfo.ServerName = My.Settings.ConnectionString.Split(";")(0).Split("=")(1)
.DatabaseName = My.Settings.ConnectionString.Split(";")(1).Split("=")(1)
.UserID = My.Settings.ConnectionString.Split(";")(3).Split("=")(1)
.Password = My.Settings.ConnectionString.Split(";")(4).Split("=")(1)
End With
'Set database connection for all tables in report
CrTables = cr.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
' Loop through each section and find report objects
Dim crReportobjects As ReportObjects, crSubReportobject As SubreportObject, subReportDocument As ReportDocument
Dim crDatabase As Database
Dim crSections As Sections = cr.ReportDefinition.Sections
For Each crSection As Section In crSections
crReportobjects = crSection.ReportObjects
For Each crReportobject As ReportObject In crReportobjects
If crReportobject.Kind = ReportObjectKind.SubreportObject Then
' If a subreport is found cast as subreportobject
crSubReportobject = CType(crReportobject, SubreportObject)
'Open the sub report
subReportDocument = crSubReportobject.OpenSubreport(crSubReportobject.SubreportName)
crDatabase = subReportDocument.Database
CrTables = crDatabase.Tables
' Loop through each table in the sub report and set the connection info
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
End If
Next
Next
If Not chkSelectClient.Checked Then
'Show all invoices
cr.RecordSelectionFormula = "{Invoices.invoice_date} in {?StartDate} to {?EndDate} and {Subject_Names.primary_name} and {Clients.billing_cycle} = {?Filter_BillingCycle}"
Else 'Invoice Number report parameter cr.SetParameterValue("Filter_InvoiceNumber", Me.cboInvoices.Text.Trim)
cr.RecordSelectionFormula = "{Subject_Names.primary_name} and {Invoices.invoice_number} = {?Filter_InvoiceNumber} and {Clients.billing_cycle} = {?Filter_BillingCycle}"
End If
'Set report parameters
cr.SetParameterValue("StartDate", Me.dtpStart.Value)
cr.SetParameterValue("EndDate", Me.dtpEnd.Value)
cr.SetParameterValue("Filter_BillingCycle", I If(Me.optMonthly.Checked, "Monthly", "Weekly"))
cr.SetParameterValue("location_id", Me.locationNameComboBox.SelectedValue cr.SetParameterValue("Billing_Contact", Billing_Contact.ToString())
'Show report
With CrystalReportViewer1
.ReportSource = cr
.Zoom(100)
.DisplayGroupTree = False
.Visible = True
.Refresh()
End With
End Sub
Thank you
Don
i am using crystal report viewer to view the report and so i have imported the references as below
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Windows
If i dispose the report once it is generated then i cant navigate to the next page. It says object reference set to null. so i didnt use it here .
I am using crystal reports that come with vs2008 .
I think it uses crystal reports 10.5 assemblies.
Used cr as reportdocument()
insted used cr as reportname()
this fixed my problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.