I am developing a Web based ERP system in .Net Mvc (C#). Crystal report working fine when i right click and select Preview report but from controller code stream line through following error
Failed to open the connection. EmployeeSalarySlip 2552_13532_{73198340-CA04-42B3-8D84-4637CE8CE81E}.rpt Details: [Database Vendor Code: 17 ]
found some solutions but did not work for me
Controller code:
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 config contain following info for connection