Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4943
  • Last Modified:

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

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
FIM2003
Asked:
FIM2003
  • 4
1 Solution
 
vastoCommented:
Looks like the session variable is not set
0
 
FIM2003Author Commented:
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
 
AndyAinscowCommented:
What is Response ?  Should that be set to something ?
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FinancialAidInfo");
0
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!

 
FIM2003Author Commented:
0
 
FIM2003Author Commented:
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
 
FIM2003Author Commented:
This resolved the issue for me.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now