【发布时间】:2020-02-19 06:04:45
【问题描述】:
我有方法,我正在使用水晶决策报告,它会抛出一个内部异常。我该如何解决这个问题?我见过类似的话题,但我的并没有真正解决类似的问题,因为我试图做同样的事情。请参阅下面的逻辑和屏幕截图以获取更多详细信息。换句话说,我的加载方法没有打开。
// 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>
【问题讨论】:
-
抛出了什么错误?请edit您的问题包含它
-
在这里我似乎有点明白为什么,现在正忙着尝试使用 Crystalreport 修复以完全安装在我的目标 IDE 上。我还注意到我没有将指向我的正确表的数据源映射到存储过程来运行原因,所以现在我得到了装配的 conflix 错误。
标签: c# sql-server asp.net-mvc