Skip to Content

Crystal Reports gives 'Invalid Subreport Name' error in vs2017

I have been given a legacy ASP.Net application written in vs2005 with CR 8. I am currently running vs2017 and CR 13.0.22.

The application shows multiple reports and I was asked to modify 1 of them that is a parent report with 5 subreports. When I initially started work I ran the Verify Database and was prompted to connect using schema/XML files that did not make it into the new code base and are now lost.

I created the 6 datasets/connections that connect to stored procedures for the data and refactored all 6 reports to reconnect to the new datasets.

Now when I run the application I get the above mentioned error: Invalid Subreport Name

Here is the method that is generating the error:

public void GenerateReport(List<Report> Reports, CrystalReportViewer Viewer)
{
int rptcount;
Report mainreport;

// make sure there is only one main report in the list
rptcount = 0;
mainreport = null;
foreach (Report report in Reports)
{
if (report.IsSubReport == false)
{
rptcount = rptcount + 1;
mainreport = report;
}
}
if (rptcount != 1)
throw new Exception("ReportWriter.GenerateReport: There was more than one main report found in the list of reports. " +
"Only one can be the main report. The other reports have to be subreports.");

// generate the report
checkReportFile(mainreport.ReportName);
document = new ReportDocument();
document.Load(mainreport.ReportName);
document.SetDataSource(mainreport.DataSet);

/* Here is where the error occurred first with the setReportParameters call. I moved it below and now the error

occurs within the foreach loop on the first iteration. */

// attach sub reports to the main report
foreach (Report report in Reports)
{
if (report.IsSubReport == true)

/* This line throws the error */
document.OpenSubreport(report.ReportName).SetDataSource(report.DataSet);
}
/* Moved to here */
setReportParameters(document, mainreport.ReportParameters);
Viewer.ReportSource = document;
}

While in debug I stopped the code prior to the iteration of the failing line: 'document.OpenSubreport(...'

I entered the first part of the code (without the SetDataSource) in the immediate window and the immediate window threw the same error. How do I track down the issue?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jan 02 at 02:07 PM

    Hi Eric,

    SP's require parameters to be set before the log on is called. Error is likely due to a failed connection for that subreport.

    Also, since you are connecting to SP's I suggest changing the reports to connect to the SP directly rather than a DS. Less memory is used so you don't have to cycle IIS as often and more efficient than using DS's, they do have limits in size.

    I also suggest updating to SP 24, I have not seen one bug reported using it.

    Here's the link with all of the info:

    https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

    Don

    Add comment
    10|10000 characters needed characters exceeded