cancel
Showing results for 
Search instead for 
Did you mean: 

Tutorial "Reading and Setting Discrete Parameters" fails intermittantly

Former Member
0 Kudos

I am using Visual Studio.Net 2003 with Crystal Reports 2008 (30 day evaluation) and writing a windows forms app in C++.

I ran through the tutorial and got it work quite nicely - or so I thought.

Once I had gone through the tutorial I made my own application doing pretty much exactly the same thing and sort of got this working too.

I say "sort of" because it doesn't always work. After fighting with it for some time I went back to the tutorial app and found that it has the same problem.

The report loads and runs but when I select Cities from the ListBox and click the "Redisplay Reports" button again and again, it eventually fails with an error "Load Report Failed". Sometimes it happens quite quickly (like the 3rd attempt) but other times it can take 10 minutes of trying before it fails.

On my own app it breaks a bit more frequently but is also completely intermittant.

The code where it is having a problem is here:

private: System::Void redisplay_Click(System::Object * sender, System::EventArgs * e)

{

ArrayList* arrayList = new ArrayList();

IEnumerator* myEnumerator = defaultParameterValuesList->SelectedItems->GetEnumerator();

while ( myEnumerator->MoveNext() )

{

String* item = dynamic_cast<String*>( myEnumerator->Current );

arrayList->Add( item );

}

String* reportPath = String::Concat( Application::StartupPath, S"
", S"CustomersByCity.rpt" );

crystalReportViewer->ReportSource = reportPath;

ParameterFields* parameterFields = crystalReportViewer->ParameterFieldInfo; // This is the line of code which fails!!!!!!!

SetCurrentValuesForParameterField( parameterFields, arrayList );

}

When the error "Load Report Failed" is displayed, I click ok, and it usually pops up again, click ok again and it breaks in the code. I trace it back to the 2nd last line of code above where I find parameterFields is undefined.

I sometimes get another problem on the same line of code - when I click the button (to run this code) the application sometimes freezes - breaking into the application I always find that it is sitting waiting for the call crystalReportView->ParameterFieldInfo to return.

So it looks to me like the problem is inside the CrystalReportViewer object.

This is extremely annoying and I can't seem to find a solution for it, can anyone help?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Often this issue is due to the report object not being destroyed after you are done with it. Try to add:

report.close()

report.dispose()

After each report is run

Ludek

Former Member
0 Kudos

When you say "report object" are you referring to the CrystalReportViewer object?

I'll give it a try - thanks.

former_member183750
Active Contributor
0 Kudos

try to modify your code a bit as:

Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

crReportDocument.Load("C:\Crystal\crnet\vbnet_win_simplepreviewreport\World Sales Report.rpt")

''''' your code here

'Bind the report to the viewer

CrystalReportViewer1.ReportSource = crReportDocument

crReportDocument.close()

crReportDocument.dispose()

In this way. we'll be using the CR report engine, rather than the viewer. The viewer is nice a quick to code, but with limited control over it. The engine has more properties and you can control what it does.

Ludek

Former Member
0 Kudos

I'm very new to this so please bear with me; I tried a few things with your suggestion but can't quite get it to work.

I created a global instance of the ReportDocument (as opposed to local within the scope of the Click function) and initialised it in the InitializeComponent method:

this->crReportDocument = new ReportDocument();

Then I modified my code like this:

private: System::Void redisplay_Click(System::Object * sender, System::EventArgs * e)

{

ArrayList* arrayList = new ArrayList();

IEnumerator* myEnumerator = defaultParameterValuesList->SelectedItems->GetEnumerator();

while ( myEnumerator->MoveNext() )

{

String* item = dynamic_cast<String*>( myEnumerator->Current );

arrayList->Add( item );

}

//Bind the report to the viewer

crReportDocument->Load( S"C:
Projects
Test
Reports
CustomersByCity.rpt" );

itbReportViewer->ReportSource = crReportDocument;

ParameterFields* parameterFields = crystalReportViewer->ParameterFieldInfo;

SetCurrentValuesForParameterField( parameterFields, arrayList );

crReportDocument->Close();

crReportDocument->Dispose();

}

I am obviously doing something wrong here, I get an error "Object reference not set to an instance of an object.

What am I doing wrong?

former_member183750
Active Contributor
0 Kudos

Perhaps a better way to approach this is to download a few sample apps and see how things work there. There is a number of samples in [this|https://smpdl.sap-ag.de/~sapidp/012002523100006252822008E/net_win_smpl.exe]

self extracting executable.

In particular have a look at vbnet_win_paramengine. Leave out the arrays for now, just hard code things.

There are more samples here:

http://www.businessobjects.com/jump/xi/default.asp

and here:

https://boc.sdn.sap.com/dotnet/samples

And I often find this White Paper useful:

http://www.businessobjects.com/global/pdf/dev_zone/VS2005_Walkthroughs.pdf

Ludek

Former Member
0 Kudos

This has got me a little closer I think but I can't quite work it all out.

The sample is in VB and I'm using C++ but I can translate the language things without a problem. I am not used to the VB way of doing things but it seems that the sample is using the report in an embedded manner whereas I am using the report outside of the application. I think I have managed to get round this particular issue and more or less copying the code and then doing some minor adaptions I got it to load a report using the ReportDocument object - fantastic!

But I can't work out how to use the close and dispose part in order to select another parameter and then reload the report.

I am unsure when I am supposed to close and dispose - at the start of my function to reload sort of seems logical as I would guess that only when I want to load a new report do I first dispose of the old one, but I can't get it to work.

Thanks for your help on this, it is definetly moving me forward.

Former Member
0 Kudos

I have got it working and it now works ALL the time.

Thanks very much for the help!

Edited by: Stefan Patten on Sep 8, 2008 12:37 PM

Answers (0)