Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-04-25
6
4,372 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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