Solved

Crystal Reports - Object reference not set to an instance of an object

Posted on 2014-04-25
6
4,444 Views
Last Modified: 2014-04-30
Crystal Reports 2008 SP4
ASP.NET 2.0
Visual Studio 2005

Getting an "Object reference not set to an instance of an object." error when trying to export my report to a pdf.

using (ReportDocument report = new ReportDocument())
{
    report.Load(Server.MapPath("FinancialAidInfo.rpt"));
    CrystalDecisions.CrystalReports.Engine.TextObject txtNotes = ((CrystalDecisions.CrystalReports.Engine.TextObject)report.ReportDefinition.ReportObjects["txtNotes"]);
    txtNotes.Text = notes;
    report.SetParameterValue("@Quarter", Session["Quarter"].ToString());
    report.SetParameterValue("@Year", Session["Year"].ToString());
    report.SetParameterValue("@Campusid", Session["Campusid"].ToString());
    report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FinancialAidInfo");
}

Open in new window


If I comment the three SetParameterValue lines out, the report will export, just with the data that was inputted into the "Main Report Preview" of the rpt file, but with those three lines passing the parameters, the error occurs at
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FinancialAidInfo");

Open in new window

0
Comment
Question by:FIM2003
  • 4
6 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 40022791
Looks like the session variable is not set
0
 

Author Comment

by:FIM2003
ID: 40022797
vasto: I was using this:

string strQtr = Session["Quarter"].ToString();
string strYr = Session["Year"].ToString();
string strCID = Session["Campusid"].ToString();
report.SetParameterValue("@Quarter", strQtr);
report.SetParameterValue("@Year", strYr);
report.SetParameterValue("@Campusid", strCID);

Open in new window


and went through checking the values with a breakpoint and all three variables have values.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40022828
What is Response ?  Should that be set to something ?
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FinancialAidInfo");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:FIM2003
ID: 40022851
0
 

Accepted Solution

by:
FIM2003 earned 0 total points
ID: 40022883
I have resolved the problem. Had something to do with being able to access the report security wise. Adding this code before setting the parameter values fixed it:

foreach (CrystalDecisions.Shared.IConnectionInfo connection in report.DataSourceConnections)
{
    connection.IntegratedSecurity = true;
}

Open in new window

0
 

Author Closing Comment

by:FIM2003
ID: 40031579
This resolved the issue for me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question