cancel
Showing results for 
Search instead for 
Did you mean: 

"Object reference not set to an instance of an object." on parametrized reports

Former Member
0 Kudos

For some reason, running reports that are parametrized (prompt for params) returns the following error: "Object reference not set to an instance of an object." Reports without the parameter prompt seems to load just fine. Here is my setup:

Windows Server 2008 R2

Microsoft Visual C++ 2010 x86 Redistributable (v10.0.30319)

MySQL Connector/ODBC 5.3, 32-bit (v5.3.4)

Microsoft .NET Framework 4.5.1 (v 4.5.50938)

SAP Crystal Reports runtime engine for .NET Framework 4 (32-bit) (v13.0.12.1494)

I have tried downgrading the CR runtime to each version down to 13.0.2 with no success. Any ideas how to proceed from here?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Hi Rocky

What's the code? Basic flow would be:

load report

log on to the database

set the parameters

view / print / export

If you are setting the parameters before you log on to the database, you will receive errors.

Also, if this is a web app, make sure the reports are placed in session.

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

public partial class _Default : System.Web.UI.Page

{

    CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument;

    protected void Page_Init(object sender, EventArgs e)

    {

        ConfigureCrystalReports();

    }

    private void ConfigureCrystalReports()

    {

        String gid = System.Guid.NewGuid().ToString("N");

        String rptPath = "path/to/reports/";

        String rptFile = "CrystalReport1.rpt";

        if(Request["rpt"] != null) {

            rptFile = Request["rpt"];

        }

        crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        crReportDocument.Load(rptPath+rptFile, CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy);

        CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

        crConnectionInfo.ServerName = (String)GetGlobalResourceObject("WebResources", "ServerName");

        crConnectionInfo.DatabaseName = (String)GetGlobalResourceObject("WebResources", "DatabaseName");

        crConnectionInfo.UserID = (String)GetGlobalResourceObject("WebResources", "UserID");

        crConnectionInfo.Password = (String)GetGlobalResourceObject("WebResources", "Password");

        UpdateConnectionInfo(crReportDocument.Database, crConnectionInfo);

        foreach (CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreport in crReportDocument.Subreports)

        {

            UpdateConnectionInfo(crSubreport.Database, crConnectionInfo);

        }

        crReportDocument.Refresh();

      

        Session["rpt_"+gid] = (CrystalDecisions.CrystalReports.Engine.ReportDocument)crReportDocument;

        Response.Redirect("viewer.aspx?gid=" + gid);

      

    }

    private void UpdateConnectionInfo(CrystalDecisions.CrystalReports.Engine.Database crDatabase, CrystalDecisions.Shared.ConnectionInfo crConnectionInfo)

    {

        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crDatabase.Tables)

        {

            CrystalDecisions.Shared.TableLogOnInfo crTableLogOnInfo = (CrystalDecisions.Shared.TableLogOnInfo)crTable.LogOnInfo.Clone();

            crTableLogOnInfo.ConnectionInfo = crConnectionInfo;

            crTable.ApplyLogOnInfo(crTableLogOnInfo);

        }

    }

}

Passes the session data to the viewer page


public partial class _Viewer : System.Web.UI.Page

{

    CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument;

    protected void Page_Init(object sender, EventArgs e)

    {

        ConfigureCrystalReports();

    }

    protected void Page_Unload(object sender, EventArgs e)

    {

        if (crReportDocument != null)

        {

            crReportDocument.Close();

            crReportDocument.Dispose();

        }

    }

    private void ConfigureCrystalReports()

    {

        String gid = (String)Request["gid"];

        if (gid != "" && Session["rpt_"+gid] != null)

        {

            crReportDocument = (CrystalDecisions.CrystalReports.Engine.ReportDocument)Session["rpt_"+gid];

            CrystalReportViewer1.ReportSource = crReportDocument;

            CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

            CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;

            CrystalReportViewer1.Visible = true;

        }

        else

        {

            Response.Redirect("expired.htm");

        }

    }

}

May be worth noting that I have an existing server that has been running this code successfully for quite a while. So I am unsure as to why this particular instance has decided to not work. Everything is running identically to my knowledge, but please let me know if there are also some server settings that I should be looking at, that is if the code looks fine.

former_member183750
Active Contributor
0 Kudos

Ok, so the code works on many other computers, except this one(?). If that is the case, then the question would be; what's the diff?

OS?

Runtime? (Use Modules to compare)

Permissions? Fiddler may give you a clue.

And my personal preference as far as teh code would be to place this:


crReportDocument.Refresh();          Session["rpt_"+gid] = (CrystalDecisions.CrystalReports.Engine.ReportDocument)crReportDocument; 

Response.Redirect("viewer.aspx?gid=" + gid); 


after



private void UpdateConnectionInfo(CrystalDecisions.CrystalReports.Engine.Database crDatabase, CrystalDecisions.Shared.ConnectionInfo crConnectionInfo)      { 

foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crDatabase.Tables) 

       { 

            CrystalDecisions.Shared.TableLogOnInfo crTableLogOnInfo = (CrystalDecisions.Shared.TableLogOnInfo)crTable.LogOnInfo.Clone(); 

            crTableLogOnInfo.ConnectionInfo = crConnectionInfo; 

            crTable.ApplyLogOnInfo(crTableLogOnInfo); 

        } 

    } 

- Ludek

Former Member
0 Kudos

Thanks Ludek. It looks like I am already placing that code after my UpdateConnectionInfo() calls, though? I will also check those tools you mentioned.

By tinkering around last night, I managed to get it running by removing the crReportDocument.Close() and crReportDocument.Dispose() from the Page_Unload method. Hopefully there won't be any negative side effects as far as report disposal goes now (still have a session timeout at 30), but at least it works.

Answers (0)