locked
Pass Parameter to Crystal Report in asp.net RRS feed

  • Question

  • User-1281668302 posted

    Hi all,

    I was trying to pass parameter from my code behind into my crystal report but I keep getting error Load Report Failed

    I use dataset to pass the parameter to crystal report. My dataset has 1 column (Test1)

    here is my code in code behind

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Dim path As String = Server.MapPath("~\Reports\CrystalReportTest.rpt")
            Dim rptDoc As ReportDocument = New ReportDocument
            rptDoc.SetDatabaseLogon("test", "test", "TestDB", "JulianPC", True) -> got error on this line when tried putting breakpoint
            Dim a As String = "10001"
            Dim b As String = "10003"
            rptDoc.Load(path)
            rptDoc.FileName = "CrystalReportTest.rpt"
            rptDoc.SetParameterValue("Test1", a)
            CrystalReportViewer1.ReportSource = rptDoc
            CrystalReportViewer1.Visible = True
        Catch ex As Exception
    
        End Try
    End Sub

    here is my aspx code

    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CrystalReportTest.rpt"></Report>
        </CR:CrystalReportSource>
        <table>
            <tr>
                <td>
                     <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" ReportSourceID="CrystalReportSource1" AutoDataBind="True" HasPrintButton="True" HasRefreshButton="True" ReuseParameterValuesOnRefresh="True" Height="50px" Width="350px"/>
                </td>
            </tr>
        </table>

    Could anyone tell me how to fix this?

    Thanks in advance for any help

    Saturday, July 19, 2014 3:04 PM

All replies

  • User489113254 posted
    ReportDocument rd = new ReportDocument();
    rd.Load(Server.MapPath(youreport));
    rd.SetParameterValue("@evaluation_archive_id", yourvalue);
               
    crReportViewer.ReportSource = rd;
    

    Saturday, July 19, 2014 3:42 PM
  • User489113254 posted
     private void SetLogOnInfo(ReportDocument rd)
            {
                CrystalDecisions.CrystalReports.Engine.Database crDatabase;
                CrystalDecisions.CrystalReports.Engine.Tables crTables;
                TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
                ConnectionInfo cinfo = new ConnectionInfo();
    
                cinfo.ServerName = 
                cinfo.DatabaseName = 
                cinfo.UserID = 
                cinfo.Password =            
                
    
                crDatabase = rd.Database;
                crTables = crDatabase.Tables;
    
                for (int i = 0; i < crTables.Count; i++)
                {
                    crTableLogOnInfo = crTables[i].LogOnInfo;
                    crTableLogOnInfo.ConnectionInfo = cinfo;
                    crTables[i].ApplyLogOnInfo(crTableLogOnInfo);
                    if (crTables[i].TestConnectivity())
                    {
                        if (crTables[i].Location.IndexOf(".") > 0)
                        {
                            crTables[i].Location = crTables[i].Location.Substring(crTables[i].Location.LastIndexOf(".") + 1);
                        }
                        else crTables[i].Location = crTables[i].Location;
                    }
    
                }
    
            }
    

    Saturday, July 19, 2014 3:46 PM
  • User-1281668302 posted

    ReportDocument rd = new ReportDocument();
    rd.Load(Server.MapPath(youreport));
    rd.SetParameterValue("@evaluation_archive_id", yourvalue);
               
    crReportViewer.ReportSource = rd;

    Actually it's the same as my code

    I've tried using @ before my report variable name

    Saturday, July 19, 2014 3:52 PM
  • User-578610739 posted

    Hi Dear,

    Load report failed is not that you understand. Its is a common error we get while working with crystal report.

    There is several reason, but not passing the parameter issue.

    1. When your file is not get from passing path or not exist.

    2. Proper permission to access of report path.

    3. While report process is going on, it needs a temp path to temporary file. By default Temp folder of your user directory or local iis path. It needs proper permission.

    4. Some time, memory leaks issue. I always got this error with this reason in production site and in local dev. this error comes due to filepath. For memory leak, we set registry key and increase virtual memory too.

    Overall I say, this is the issue comes picture when the temp file is not get or not load in memory to display.

    Tuesday, July 22, 2014 12:55 AM