1. Failed to open the connection.\nDetails: [Database Vendor Code: 12154 ]\rFailed to open the connection.\nDetails: [Database Vendor Code: 12154 ]\rFailed to open the connection.\nSubScription2 {052A197A-58FE-454F-AD33-09EA7676B95B}.rpt\nDetails: [Database Vendor Code: 12154
2. Logon failed.
Error in File SubScription2 {D8E9A692-C93D-47AD-B84B-52ADD7DCC3B8}.rpt:
Unable to connect: incorrect log on parameters.
3. Database logon failed.
4. Missing parameter
Solv all those above error by using this code
-----------------------------------------------------------------------
โค้ด: เลือกทั้งหมด
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public ActionResult DetailsReport()
{
string paramSSID = "123456789";
Sections crSections;
ReportDocument crReportDocument, crSubreportDocument;
SubreportObject crSubreportObject;
ReportObjects crReportObjects;
ConnectionInfo crConnectionInfo;
Database crDatabase;
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
crReportDocument.Load(Server.MapPath("~/Reports/SubScription2.rpt"));
crReportDocument.SetParameterValue("SSID", paramSSID);
//set parameter for each subreport
crReportDocument.SetParameterValue("SSID", paramSSID, "CA");
crReportDocument.SetParameterValue("SSID", paramSSID, "TD");
crReportDocument.SetParameterValue("SSID", paramSSID, "ATM");
crReportDocument.SetParameterValue("SSID", paramSSID, "Saving");
crReportDocument.SetParameterValue("SSID", paramSSID, "IVR");
crReportDocument.SetParameterValue("SSID", paramSSID, "IB");
crReportDocument.SetParameterValue("SSID", paramSSID, "CIB");
crReportDocument.SetParameterValue("SSID", paramSSID, "SMS");
crReportDocument.SetParameterValue("SSID", paramSSID, "ATS");
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = "(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.1)(PORT=5555))(CONNECT_DATA=(SERVICE_NAME=CUS)))";
crConnectionInfo.UserID = "User01";
crConnectionInfo.Password = "password";
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
{
crTableLogOnInfo = aTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
aTable.ApplyLogOnInfo(crTableLogOnInfo);
}
crSections = crReportDocument.ReportDefinition.Sections;
// loop through all the sections to find all the report objects
foreach (Section crSection in crSections)
{
crReportObjects = crSection.ReportObjects;
//loop through all the report objects in there to find all subreports
foreach (ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
crSubreportObject = (SubreportObject)crReportObject;
//open the subreport object and logon as for the general report
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
crDatabase = crSubreportDocument.Database;
crTables = crDatabase.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
{
crTableLogOnInfo = aTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
aTable.ApplyLogOnInfo(crTableLogOnInfo);
}
}
}
}
crReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, true, "SubscribeReport");
return View();
}