G
Guest
Hi,
It looks like posting a question on Sunday was not a good Idea that why I'm
trying it Today.
I'm using this code to run a crystal report and export it to pdf, and when
running it it in debug mode it working fine, but from the browser it's fails
to run telling me that the Crystal report failed to Login!!?
private void SetDBLogonForReport(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
private void SetDBLogonForSubreports(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject =
(SubreportObject)reportObject;
ReportDocument subReportDocument =
subreportObject.OpenSubreport(subreportObject.SubreportName);
SetDBLogonForReport(connectionInfo, subReportDocument);
}
}
}
}
private void GenerateInspectionReport()
{
ReportDocument O_Report = new ReportDocument();
string strReportPath = Request.PhysicalApplicationPath +
"\\InspectionReport.rpt";
string strPDF_Path = MyPath + "\\";
O_Report.Load(strReportPath);
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "civicview";
connectionInfo.DatabaseName = "civicview";
connectionInfo.UserID = "_SYSTEM";
connectionInfo.Password = "SYS";
SetDBLogonForReport(connectionInfo, O_Report);
SetDBLogonForSubreports(connectionInfo, O_Report);
ParameterValues currentParameterValues = new ParameterValues();
ParameterDiscreteValue parameterDiscreteValue = new
ParameterDiscreteValue();
parameterDiscreteValue.Value = "275";
currentParameterValues.Add(parameterDiscreteValue);
ParameterFieldDefinitions parameterFieldDefinitions =
O_Report.DataDefinition.ParameterFields;
ParameterFieldDefinition parameterFieldDefinition =
parameterFieldDefinitions["EvaluationID"];
parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
O_Report.ExportToDisk(ExportFormatType.PortableDocFormat,
strPDF_Path + "InspectionReport.pdf");
O_Report.Close();
O_Report.Dispose();
}
Thanks
It looks like posting a question on Sunday was not a good Idea that why I'm
trying it Today.
I'm using this code to run a crystal report and export it to pdf, and when
running it it in debug mode it working fine, but from the browser it's fails
to run telling me that the Crystal report failed to Login!!?
private void SetDBLogonForReport(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
private void SetDBLogonForSubreports(ConnectionInfo connectionInfo,
ReportDocument reportDocument)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject =
(SubreportObject)reportObject;
ReportDocument subReportDocument =
subreportObject.OpenSubreport(subreportObject.SubreportName);
SetDBLogonForReport(connectionInfo, subReportDocument);
}
}
}
}
private void GenerateInspectionReport()
{
ReportDocument O_Report = new ReportDocument();
string strReportPath = Request.PhysicalApplicationPath +
"\\InspectionReport.rpt";
string strPDF_Path = MyPath + "\\";
O_Report.Load(strReportPath);
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "civicview";
connectionInfo.DatabaseName = "civicview";
connectionInfo.UserID = "_SYSTEM";
connectionInfo.Password = "SYS";
SetDBLogonForReport(connectionInfo, O_Report);
SetDBLogonForSubreports(connectionInfo, O_Report);
ParameterValues currentParameterValues = new ParameterValues();
ParameterDiscreteValue parameterDiscreteValue = new
ParameterDiscreteValue();
parameterDiscreteValue.Value = "275";
currentParameterValues.Add(parameterDiscreteValue);
ParameterFieldDefinitions parameterFieldDefinitions =
O_Report.DataDefinition.ParameterFields;
ParameterFieldDefinition parameterFieldDefinition =
parameterFieldDefinitions["EvaluationID"];
parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
O_Report.ExportToDisk(ExportFormatType.PortableDocFormat,
strPDF_Path + "InspectionReport.pdf");
O_Report.Close();
O_Report.Dispose();
}
Thanks