I have made a crystal report in asp.net for web application. Some report open nicely. But sometimes it does not. It shows the following problem.
Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: [COMException (0x8002000b): Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))]
Report_Viewer.Page_Load(Object sender, EventArgs e) +894
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927
My VS: VS 2008, Database:MS SQL Express 2005, OS:Windows 7
Is there any one to solve my problem..
NB: My code is in a Class
public ReportDocument ShowReport(string ReportName, string Parameter1)
{
try
{
cryRpt.Load(ReportName);
cryRpt.SetDatabaseLogon(UserName, Password, ServerName, DatabaseName);
crParameterValues.Clear();
crParameterDiscreteValue.Value = Parameter1;// as like Parameter1
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["@Parameter1"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
}
catch (Exception ex)
{
throw ex;
//ShowReport(@"default_report.rpt");
}
//CleareParameter();
return cryRpt;
}
Report Viewer Page load
protected void Page_Load(object sender, EventArgs e)
{
string ReportName="";
string Parameter1="";
ReportName= Session["ReportName "].ToString();
Parameter1 = Session["Parameter1"].ToString();
}
try
{
if (Session["Parameter2"].ToString() != null)
{
Parameter2 = Session["Parameter2"].ToString();
icount = icount + 1;
}
}
catch (Exception ) { }
ReportViewer oReportViewer = new ReportViewer(); // Class file
ReportDocument rptDoc = new ReportDocument();
try
{
rptDoc = oReportViewer.ShowReport(ReportName, Parameter1);
rptDoc = oReportViewer.ShowReport(ReportName, Parameter1,
rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "Report");
CrystalReportViewer1.ReportSource = rptDoc;
}
catch (Exception ex)
{
throw ex;
}
}