crystal report failed to get data

2019-08-31 07:31发布

I'm new in crystal report I need some help: I have been set the report Database Logon in two ways as following:

1st: rpt.SetDatabaseLogon(userId, userPassword);

2nd: DatabaseLogOn(fullserverName, dBName, dBUser, userPassword);

the first way is working well but I need to change it to the second one for some reasons but Unfortunately it's not working and I don't know the reason:

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);

                        }
                    }
                }
            }


        }

can any one Help

1条回答
SAY GOODBYE
2楼-- · 2019-08-31 08:25

Have you checked out this post? It is almost identical to yours and the answer to the post suggests slight changes to the structure.

查看更多
登录 后发表回答