I have method and I am using crystal-decision report and its throwing an inner exception. How do I fix this issue? I have seen similar topic, but mine does not really solve similar problem as I have attempted to do the same. Please see my logic below and screen shot for more detail. In another words my load method does not open.
// Controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AdvertReport(FormCollection fc)
{
DataSet ds = obIlReports.Generate_AdvertDetailsReport();
ds.Tables[0].TableName = "Tbl_TrainingAcademy";
if(ds.Tables[0].Rows.Count > 0)
{
ReportClass rptH = new ReportClass();
rptH.FileName = Server.MapPath("~/Reports/AdvertReport.rpt");
rptH.Load(); // The document do not open error is thrown here.
rptH.SetDataSource(ds.Tables[0]);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "AdvertReport.pdf");
}
return View();
}
// Ilreport here with store procedure.
public class ReportsMaster : IlReports
{
public DataSet Generate_AdvertDetailsReport()
{
using(SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["eNtsaOnlineRegistrationDB"].ToString()))
{
con.Open();
DataSet ds = new DataSet();
// Handling Exception
try
{
SqlCommand cmd = new SqlCommand("dbo.GetAdvertReport", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
if(ds.Tables.Count > 0)
{
return ds;
}
else
{
return ds = null;
}
}
catch(Exception )
{
throw;
}
finally
{
ds.Dispose();
}
}
}
}
// ConnectionString
<connectionStrings>
<add name="eNtsaOnlineRegistrationDB" connectionString="Data Source=GcobaniM-L\SQLEXPRESS; DataBase=eNtsaOnlineRegistrationDB; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>