具有链接参数db登录的Crystal Report查看器子报表失败

2020-09-05 13:21发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

我为此进行了大量搜索,但不幸的是我找不到解决方案。 当我运行报表(如果它是单个报表)时,我可以查看它,但是如果报表包含带有链接参数的子报表,则运行该数据库时,DB登录失败。 下面是我的代码

使用系统;

使用System.Data;

使用System.Drawing;

使用System.Configuration;

使用System.Collections;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Web.UI.HtmlControls;

使用System.IO;

使用CrystalDecisions.CrystalReports.Engine;

使用CrystalDecisions.Shared;

使用CrystalDecisions.Web;

//使用CrystalDecisions.ReportAppServer;

使用CrystalDecisions.ReportAppServer.ClientDoc;

//使用CrystalDecisions.ReportAppServer.DataDefModel;

//使用CrystalDecisions.ReportAppServer.ReportDefModel;

使用System.Data.OracleClient;

命名空间Crystalreports_to_text

{

公共局部类WebForm1:System.Web.UI.Page

{

受保护的字符串countpar;

ISCDReportClientDocument rptClientDoc = new ReportClientDocument();

ReportDocument cryRpt = new ReportDocument();

受保护的无效Page_Load(对象发送者,EventArgs e)

{

如果(!IsPostBack)

{

BindDropDownList();

}

其他

{

}

}

受保护的无效Page_Init(对象发送者,EventArgs e)

{

}

私人空白BindDropDownList()

{

字符串[]报告= Directory.GetFiles(" D:\\ Docs \\ IBS_reports_Mar_09_2016 \\"," * .rpt");

IDictionary sortedList = new SortedList();

foreach(报告中的字符串路径)

{

int reportNamePrefix = path.LastIndexOf(@" \")+ 1;

int reportNameLength = path.Length-reportNamePrefix;

字符串reportName = Path.GetFileNameWithoutExtension(path);

sortedList.Add(path,reportName);

}

DropDownList1.DataSource = sortedList;

DropDownList1.DataTextField ="值";

DropDownList1.DataValueField ="键";

DropDownList1.DataBind();

}

受保护的void DropDownList1_SelectedIndexChanged(对象发送者,EventArgs e)

{

字符串值= DropDownList1.SelectedValue;

getpar();

}

受保护的无效Button1_Click(对象发送者,EventArgs e)

{

CrV();

}

受保护的无效setDbInfo()

{

CrystalDecisions.CrystalReports.Engine.ReportObjects crReportObjects;

CrystalDecisions.CrystalReports.Engine.SubreportObject crSubreportObject;

CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreportDocument;

CrystalDecisions.CrystalReports.Engine.Database crDatabase;

TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();

TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

ConnectionInfo crConnectionInfo =新的ConnectionInfo();

表CrTables;

节crSections;

crConnectionInfo.ServerName =" SYSDSN";

crConnectionInfo.DatabaseName ="";

crConnectionInfo.UserID ="用户";

crConnectionInfo.Password ="通过";

crConnectionInfo.IntegratedSecurity = false;

crDatabase = cryRpt.Database;

CrTables = crDatabase.Tables;

foreach(CrTables中的CrystalDecisions.CrystalReports.Engine.Table aTable)

{

crtableLogoninfo = aTable.LogOnInfo;

crtableLogoninfo.ConnectionInfo = crConnectionInfo;

aTable.ApplyLogOnInfo(crtableLogoninfo);

}

//此工作表用于具有子报告的报告

//将section对象设置为当前报告的section

crSections = cryRpt.ReportDefinition.Sections;

//遍历所有部分以查找所有报告对象

foreach(crSection中的crSection部分)

{

crReportObjects = crSection.ReportObjects;

//遍历其中的所有报告对象以找到所有子报告

foreach(crReportObjects中的ReportObject crReportObject)

{

如果(crReportObject.Kind == ReportObjectKind.SubreportObject)

{

crSubreportObject =(SubreportObject)crReportObject;

//打开子报表对象并按照常规报表登录

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

crDatabase = crSubreportDocument.Database;

CrTables = crDatabase.Tables;

foreach(CrTables中的CrystalDecisions.CrystalReports.Engine.Table aTable)

{

crtableLogoninfo = aTable.LogOnInfo;

crtableLogoninfo.ConnectionInfo = crConnectionInfo;

aTable.ApplyLogOnInfo(crtableLogoninfo);

}

}

}

}

}

私有无效的getpar()

{

rptClientDoc = cryRpt.ReportClientDocument;

cryRpt.Load(DropDownList1.Text);

int z = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count;

如果(z> 0)

{

int cnt = 0;

foreach(rptClientDoc.DataDefController.DataDefinition.ParameterFields中的CrystalDecisions.ReportAppServer.DataDefModel.ParameterField参数字段)

{

cnt ++;

标签myLabel = new Label();

TextBox tx = new TextBox();

myLabel.Text = paramfield.Name.ToString()+":" +"";

myLabel.ID = paramfield.Name.ToString();

tx.ID ="文本框" + cnt;

tx.Attributes.Add(" runat"," Server");

Panel1.Controls.Add(myLabel);

Panel1.Controls.Add(tx);

Panel1.Controls.Add(new LiteralControl(" <​​br/>
")));

}

}

}

private void setpar()

{

rptClientDoc = cryRpt.ReportClientDocument;

cryRpt.Load(DropDownList1.Text);

int z = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count;

List ls = new List ();

如果(z> 0)

{

字符串controlid = string.Empty;

int cnt = 0;

foreach(rptClientDoc.DataDefController.DataDefinition.ParameterFields中的CrystalDecisions.ReportAppServer.DataDefModel.ParameterField参数字段)

{

cnt ++;

controlid ="文本框" + cnt.ToString();

TextBox tb = Panel1.FindControl(controlid)as TextBox;

字符串sValue = Request.Form [controlid];

ls.Add(新字符串[] {paramfield.Name.ToString(),sValue});

}

foreach(ls中的string []个项目)

{

cryRpt.SetParameterValue(items [0],items [1]);

}

}

}

私人空隙CrV()

{

setpar();

setDbInfo();

CrystalReportViewer1.ReportSource = cryRpt;

CrystalReportViewer1.DataBind();

}

}

}

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

我为此进行了大量搜索,但不幸的是我找不到解决方案。 当我运行报表(如果它是单个报表)时,我可以查看它,但是如果报表包含带有链接参数的子报表,则运行该数据库时,DB登录失败。 下面是我的代码

使用系统;

使用System.Data;

使用System.Drawing;

使用System.Configuration;

使用System.Collections;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Web.UI.HtmlControls;

使用System.IO;

使用CrystalDecisions.CrystalReports.Engine;

使用CrystalDecisions.Shared;

使用CrystalDecisions.Web;

//使用CrystalDecisions.ReportAppServer;

使用CrystalDecisions.ReportAppServer.ClientDoc;

//使用CrystalDecisions.ReportAppServer.DataDefModel;

//使用CrystalDecisions.ReportAppServer.ReportDefModel;

使用System.Data.OracleClient;

命名空间Crystalreports_to_text

{

公共局部类WebForm1:System.Web.UI.Page

{

受保护的字符串countpar;

ISCDReportClientDocument rptClientDoc = new ReportClientDocument();

ReportDocument cryRpt = new ReportDocument();

受保护的无效Page_Load(对象发送者,EventArgs e)

{

如果(!IsPostBack)

{

BindDropDownList();

}

其他

{

}

}

受保护的无效Page_Init(对象发送者,EventArgs e)

{

}

私人空白BindDropDownList()

{

字符串[]报告= Directory.GetFiles(" D:\\ Docs \\ IBS_reports_Mar_09_2016 \\"," * .rpt");

IDictionary sortedList = new SortedList();

foreach(报告中的字符串路径)

{

int reportNamePrefix = path.LastIndexOf(@" \")+ 1;

int reportNameLength = path.Length-reportNamePrefix;

字符串reportName = Path.GetFileNameWithoutExtension(path);

sortedList.Add(path,reportName);

}

DropDownList1.DataSource = sortedList;

DropDownList1.DataTextField ="值";

DropDownList1.DataValueField ="键";

DropDownList1.DataBind();

}

受保护的void DropDownList1_SelectedIndexChanged(对象发送者,EventArgs e)

{

字符串值= DropDownList1.SelectedValue;

getpar();

}

受保护的无效Button1_Click(对象发送者,EventArgs e)

{

CrV();

}

受保护的无效setDbInfo()

{

CrystalDecisions.CrystalReports.Engine.ReportObjects crReportObjects;

CrystalDecisions.CrystalReports.Engine.SubreportObject crSubreportObject;

CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreportDocument;

CrystalDecisions.CrystalReports.Engine.Database crDatabase;

TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();

TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

ConnectionInfo crConnectionInfo =新的ConnectionInfo();

表CrTables;

节crSections;

crConnectionInfo.ServerName =" SYSDSN";

crConnectionInfo.DatabaseName ="";

crConnectionInfo.UserID ="用户";

crConnectionInfo.Password ="通过";

crConnectionInfo.IntegratedSecurity = false;

crDatabase = cryRpt.Database;

CrTables = crDatabase.Tables;

foreach(CrTables中的CrystalDecisions.CrystalReports.Engine.Table aTable)

{

crtableLogoninfo = aTable.LogOnInfo;

crtableLogoninfo.ConnectionInfo = crConnectionInfo;

aTable.ApplyLogOnInfo(crtableLogoninfo);

}

//此工作表用于具有子报告的报告

//将section对象设置为当前报告的section

crSections = cryRpt.ReportDefinition.Sections;

//遍历所有部分以查找所有报告对象

foreach(crSection中的crSection部分)

{

crReportObjects = crSection.ReportObjects;

//遍历其中的所有报告对象以找到所有子报告

foreach(crReportObjects中的ReportObject crReportObject)

{

如果(crReportObject.Kind == ReportObjectKind.SubreportObject)

{

crSubreportObject =(SubreportObject)crReportObject;

//打开子报表对象并按照常规报表登录

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

crDatabase = crSubreportDocument.Database;

CrTables = crDatabase.Tables;

foreach(CrTables中的CrystalDecisions.CrystalReports.Engine.Table aTable)

{

crtableLogoninfo = aTable.LogOnInfo;

crtableLogoninfo.ConnectionInfo = crConnectionInfo;

aTable.ApplyLogOnInfo(crtableLogoninfo);

}

}

}

}

}

私有无效的getpar()

{

rptClientDoc = cryRpt.ReportClientDocument;

cryRpt.Load(DropDownList1.Text);

int z = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count;

如果(z> 0)

{

int cnt = 0;

foreach(rptClientDoc.DataDefController.DataDefinition.ParameterFields中的CrystalDecisions.ReportAppServer.DataDefModel.ParameterField参数字段)

{

cnt ++;

标签myLabel = new Label();

TextBox tx = new TextBox();

myLabel.Text = paramfield.Name.ToString()+":" +"";

myLabel.ID = paramfield.Name.ToString();

tx.ID ="文本框" + cnt;

tx.Attributes.Add(" runat"," Server");

Panel1.Controls.Add(myLabel);

Panel1.Controls.Add(tx);

Panel1.Controls.Add(new LiteralControl(" <​​br/>
")));

}

}

}

private void setpar()

{

rptClientDoc = cryRpt.ReportClientDocument;

cryRpt.Load(DropDownList1.Text);

int z = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count;

List ls = new List ();

如果(z> 0)

{

字符串controlid = string.Empty;

int cnt = 0;

foreach(rptClientDoc.DataDefController.DataDefinition.ParameterFields中的CrystalDecisions.ReportAppServer.DataDefModel.ParameterField参数字段)

{

cnt ++;

controlid ="文本框" + cnt.ToString();

TextBox tb = Panel1.FindControl(controlid)as TextBox;

字符串sValue = Request.Form [controlid];

ls.Add(新字符串[] {paramfield.Name.ToString(),sValue});

}

foreach(ls中的string []个项目)

{

cryRpt.SetParameterValue(items [0],items [1]);

}

}

}

私人空隙CrV()

{

setpar();

setDbInfo();

CrystalReportViewer1.ReportSource = cryRpt;

CrystalReportViewer1.DataBind();

}

}

}

付费偷看设置
发送
3条回答
渐行渐远_HoldOn
1楼 · 2020-09-05 13:32.采纳回答

您注释掉的行会建立连接...

如果它在KBA中不起作用,则需要调试,可能是我正在设置一些值,所以逐行进行。

p>

或启用CRLogger并查看正在传递的内容。

Don

追夢秋陽
2楼-- · 2020-09-05 13:28

Hi Don,

我之前曾尝试过KBA,但仍然无法登录。 我在另一篇文章中找到了以下内容:

受保护的无效LogonDb()

{

///我对此并不了解,所以我将其注释掉。 //rptClientDoc.DatabaseController.SetTableLocationByServerDatabaseName(""," IBSDB"," TestDB"," sa"," sabkme");

CrystalDecisions.CrystalReports.Engine.ReportObjects crReportObjects;

CrystalDecisions.CrystalReports.Engine.SubreportObject crSubreportObject;

CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreportDocument;

CrystalDecisions.CrystalReports.Engine.Database crDatabase;

CrystalDecisions.CrystalReports.Engine.Tables crTables;

TableLogOnInfo crTableLogOnInfo;

CrystalDecisions.Shared.ConnectionInfo crConnectioninfo =新的CrystalDecisions.Shared.ConnectionInfo();

//将必要的参数传递给connectionInfo对象

crConnectioninfo.ServerName =" Oracle DSN";

crConnectioninfo.UserID ="用户ID";

crConnectioninfo.Password ="通过";

crConnectioninfo.DatabaseName ="我保持为空";

//设置数据库和表对象以引用当前报告

crDatabase = cryRpt.Database;

crTables = crDatabase.Tables;

//循环遍历所有表并传递连接信息

foreach(crTables中的CrystalDecisions.CrystalReports.Engine.Table crTable)

{

crTableLogOnInfo = crTable.LogOnInfo;

crTableLogOnInfo.ConnectionInfo = crConnectioninfo;

crTable.ApplyLogOnInfo(crTableLogOnInfo);

}

//将crSections对象设置为当前报表的各个部分

CrystalDecisions.CrystalReports.Engine.Sections crSections = cryRpt.ReportDefinition.Sections;

//循环遍历所有部分以找到所有报告对象

foreach(在crSections中的CrystalDecisions.CrystalReports.Engine.Section crSection)

{

crReportObjects = crSection.ReportObjects;

//循环遍历所有报表对象以找到所有子报表

foreach(crReportObjects中的CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject)

{

如果(crReportObject.Kind == ReportObjectKind.SubreportObject)

{

//您将需要将报表对象转换为子报表

//找到对象后

crSubreportObject =(CrystalDecisions.CrystalReports.Engine.SubreportObject)crReportObject;

//打开子报表对象

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

//设置数据库和表对象以使用子报表

crDatabase = crSubreportDocument.Database;

crTables = crDatabase.Tables;

//循环浏览子报表和

中的所有表

//设置连接信息并将其应用到表中

foreach(crTables中的CrystalDecisions.CrystalReports.Engine.Table crTable)

{

crConnectioninfo.ServerName =" Oracle DSN";

crConnectioninfo.UserID ="用户ID";

crConnectioninfo.Password ="通过";

crConnectioninfo.DatabaseName ="我保持为空";

crTableLogOnInfo = crTable.LogOnInfo;

crTableLogOnInfo.ConnectionInfo = crConnectioninfo;

crTable.ApplyLogOnInfo(crTableLogOnInfo);

}

}

}

}

//bool myTEst = rptClientDoc.DatabaseController.VerifyTableConnectivity(" Orders");

GroupPath gp = new GroupPath();

字符串tmp = String.Empty;

尝试

{

rptClientDoc.RowsetController.GetSQLStatement(gp,out tmp);

output.Text = tmp;

}

捕获(异常除外)

{

output.Text ="错误:" +例如消息;

返回;

}

}

黑丝骑士
3楼-- · 2020-09-05 13:44

Windows或WEB应用程序?

您正在使用什么运行时间?

运行时使用什么SP?

一周热门 更多>