我是水晶报告的新手,我需要一些帮助: 我已经通过以下两种方式设置报告数据库登录:
1st:rpt.SetDatabaseLogon(userId,userPassword);
2nd:DatabaseLogOn(fullserverName,dBName,dBUser,userPassword);
第一种方式运作良好,但由于某些原因我需要将其更改为第二种方式 不幸的是它没有用,我不知道原因:
public void DatabaseLogOn(string serverstring, string databasestring, string useridstring, string passwordstring)
{
var crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = serverstring;
crConnectionInfo.DatabaseName = databasestring ;
crConnectionInfo.UserID = useridstring ;
crConnectionInfo.Password = passwordstring ;
crConnectionInfo.IntegratedSecurity = true;
var crTableLogonInfo = new TableLogOnInfo();
Tables CrTables;
CrTables = rpt.Database.Tables;
foreach (Table crTable in CrTables)
{
crTableLogonInfo = crTable.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogonInfo);
}
Sections CrSections = rpt.ReportDefinition.Sections;
// loop through all the sections to find all the report objects
foreach (Section CrSection in CrSections)
{
ReportObjects 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)
{
SubreportObject CrSubreportObject = (SubreportObject)CrReportObject;
//open the subreport object and logon as for the general report
ReportDocument CrSubreportDocument = CrSubreportObject.OpenSubreport(CrSubreportObject.SubreportName);
CrTables = CrSubreportDocument.Database.Tables;
foreach (Table aTable in CrTables)
{
crTableLogonInfo = aTable.LogOnInfo;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
aTable.ApplyLogOnInfo(crTableLogonInfo);
}
}
}
}
}
可以任何一个帮助