我正在用.Net Mvc(C#)开发基于Web的ERP系统。 当我右键单击并选择“预览报告”,但从控制器代码流行通过以下错误时,Crystal报表工作正常
无法打开连接。 雇员工资单2552_13532_ {73198340-CA04-42B3-8D84-4637CE8CE81E} .rpt 详细信息:[数据库供应商代码:17]
找到了一些解决方案,但对我不起作用
控制器代码:
public ActionResult GenerateSalarySlip(int EmployeeId,int LocationId,int Year,int Month)
{
var location = db.Locations.Find(LocationId);
ReportDocument reportDocument = new ReportDocument();
string path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Reports"), "EmployeeSalarySlip.rpt").ToString();
reportDocument = Common.Common.SetUsersInfo(path);
reportDocument.SetParameterValue("@LocationId", LocationId);
reportDocument.SetParameterValue("@EmployeeId", EmployeeId);
reportDocument.SetParameterValue("@Year", Year);
reportDocument.SetParameterValue("@Month", Month);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
try
{
var exportOptions = reportDocument.ExportOptions;
exportOptions.ExportDestinationType = ExportDestinationType.NoDestination;
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//exportOptions.ExportFormatType = ExportFormatType.ExcelWorkbook;
var req = new ExportRequestContext { ExportInfo = exportOptions };
var stream = reportDocument.FormatEngine.ExportToStream(req);
stream.Seek(0, SeekOrigin.Begin);
//return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", DateTime.Now.ToShortDateString() + "-" + ".xlsx");
return File(stream, "application/pdf", DateTime.Now.ToShortDateString() + "-" + ".pdf");
}
catch (Exception ex)
{
throw;
}
return null;
}
Web配置包含以下有关连接的信息