In a web application I have code to generate a PDF file using crystal reports and both the ReportDocument.ExportToDisk and ReportDocument.ExportToStream methods. I am using the 64bit crystal runtime v13 SP31. All database data is pushed directly to each report using the SetDataSource method.
When I call the code from the code-behind of a web page, it executes perfectly and a useable pdf is generated.
For some (not all) reports in the application, when I call exactly the same code from a background task spawned using QueueBackgroundWorkItem, it behaves differently and generates exceptions. So far the kinds of exceptions I get are either a spurious "A string is required here" exception relating to a formula field in the report or a "Missing Parameters" exception relating to ALL sub-report parameters (despite all sub-report parameters being linked to equivalent main report parameters).
The problems seem to be consistent for individual reports (i.e. the same error occurs every time that report is run in the background) - but not every report in the application is affected. In each case identified so far, the report works perfectly if run from code-behind or if previewed in the report designer, but only fails when the report is generated in the background environment.
The formula field exception seems only to affect reports containing formulas fields that use conditional statements ("if" or "iif") where the condition involves a numeric field but the result is a string - something like "IIF ({NumericField} = 0, 'Zero', 'Non-Zero')
" for example. Tweaking the formula to wrap the numeric condition (e.g. "IIF (TOTEXT({NumericField}) = '0', 'Zero', 'Non-Zero')
") does NOT cure the problem.
Similarly, I have tried adding extra code to set the sub-report parameters directly (instead of allowing them to filter down from the linked main report parameters), but whatever technique I use, that also generates exceptions (it seems crystal doesn't like you trying to bypass parameter links).
As far as I can see, the crystal reports engine is behaving differently in a background setting. Is anyone aware of the physical differences there are in the environment of a background task compared to normal code-behind that could explain these behavioral differences and does anyone have any suggestions as to a remedy?
CodePudding user response:
This might be related to the process used to supply the data.
To test that theory, please test with a static data source (or simply use Saved Data).