rainforestnet / CrystalReportsNinja

A small Windows Console App that loads external Crystal Reports file, takes parameter inputs and export to various format or even print to printer
http://www.rainforestnet.com
93 stars 77 forks source link

exception: "Operation illegal on linked parameter" when running a report with sub-reports #38

Open jthvedt opened 5 years ago

jthvedt commented 5 years ago

Trying to run a report with linked sub-reports. I get this: Exception: Error in File foo.rpt: Operation illegal on linked parameter. Inner Exception: System.Runtime.InteropServices.COMException (0x80000290): Error in File foo.rpt: Operation illegal on linked parameter. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)

My working theory is that it's trying to pass parameters to the subreports, whereas those subreports should be getting those from the parent report.

sunk818 commented 5 years ago

Can you recreate the report using northwind.mdb or something that is publicly agreed upon set? Will make it easier to troubleshoot and replicate.

fearnt commented 5 years ago

Hi jthvedt, I have just faced this same issue, and after some playing around, I've found that if the parameters you are feeding into your parent report, are named the same as the sub-report parameters - you get this error.

If you rename the params in the sub report, you should be all sorted.

Thanks, TF

chubbardsr1 commented 4 years ago

For this issue, is the true solution to have unique parameter names between the parent report and the sub reports? Crystal is built to have parameter passing with no issues. Not following why this would cause a break in runtime.

chubbardsr1 commented 4 years ago

I have modified this and have an update if you would like it. Will create a fork here soon and setup for pull.

mhertzfeld commented 4 years ago

chubbards1 what did you do to fix? I'd like to include in my fork of ninja.

https://github.com/mhertzfeld/CrystalReportsNinja/tree/1.4.0.0

chubbardsr1 commented 4 years ago

Sorry for the delay @mhertzfeld Here is the code that I updated the ProcessParmeters() to. ` private void ProcessParameters() { var paramCount = _reportDoc.ParameterFields.Count;

        if (paramCount > 0)
        {
            ParameterCore paraCore = new ParameterCore(_logfilename, ReportArguments.ParameterCollection);

            paraCore.ProcessRawParameters();
            var paramDefs = _reportDoc.DataDefinition.ParameterFields;
            for (int i = 0; i < paramDefs.Count; i++)
            {
                // ParameterField parField = m_Report.ParameterFields[i];
                if(paramDefs[i].ReportName.Length > 0) {
                    // Console.WriteLine(paramDefs[i].ReportName);
                    // Console.WriteLine(paramDefs[i].ParameterFieldName);
                } else {
                    ParameterValues values = paraCore.GetParameterValues(paramDefs[i]);
                    paramDefs[i].ApplyCurrentValues(values);
                }
                //continue;  //yes, move next

            }
        }
    }`

I will start off that I am not a C# person. I made my changes and modifications based on what I leared in a couple of hours.

chubbardsr1 commented 4 years ago

ReportProcessor.zip

The zip has all of the little changes that I did to the ReportProcessor.cs. I added a little more Console Write lines so I could see what parts were kicking out, or running. Biggest one is the "Status:100" I look for at the end in my auto process so I know the report was created.

mhertzfeld commented 4 years ago

@chubbardsr1

I don't have a report handy to test this with so I have a few questions.

Under what conditions were you seeing the reportname with a length greater than 0?

Under what conditions were you seeing the reportname with a length of 0?

chubbardsr1 commented 4 years ago

Sub Reports. They were the only time they would have a condition > 0. Pulled this from: https://stackoverflow.com/questions/22006034/operation-illegal-on-linked-parameter-crystal-report

mhertzfeld commented 4 years ago

@chubbardsr1 I've added your fix to my code.

https://github.com/mhertzfeld/CrystalReportsNinja/commit/c166eaa52f655476c0abe9c0cc70d4c8e3a62acb

The fix currently exists in the branch below. The branch includes compiled executables that include your fix.

https://github.com/mhertzfeld/CrystalReportsNinja/tree/1.4.0.0

mhertzfeld commented 4 years ago

@chubbardsr1 for some reason the fix you provided is not working for me and a few other users.

I found a different solution that you can test in the branch linked below.

https://github.com/mhertzfeld/CrystalReportsNinja/tree/1.4.0.0

chubbardsr1 commented 4 years ago

I was testing and tried out your fix in the branch and that seems to be working much better. One issue I ran in to, is I have a report with multiple SubReports. The subreports are linked for the parameters, but the sub links will show false for IsLinked at random. I can run the report 10 times and it will fail 3-5 times. It's weird. Nothing to do with the console code. Sometime with the runtime from what I can see. I wasn't able to find a solution to this yet. But your code does seem to be cleaner and I've updated mine to that as well.