Solved

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

Posted on 2014-04-25
6
4,070 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
Comment Utility
Looks like the session variable is not set
0
 

Author Comment

by:FIM2003
Comment Utility
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
Comment Utility
What is Response ?  Should that be set to something ?
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "FinancialAidInfo");
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:FIM2003
Comment Utility
0
 

Accepted Solution

by:
FIM2003 earned 0 total points
Comment Utility
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
Comment Utility
This resolved the issue for me.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XML to SQL Table using c# 5 42
Pass through dll 2 32
Visual Studio: built-in keystroke automation 2 20
Problem to page 4 11
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now