Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

Report won't logon to database if report uses parameters

$
0
0

I've got a 64-bit viewer running on WS2012.  Reports without parameters work properly, they connect to the database and show correctly.  But if properties need to be set, I get the dreaded "Database logon failed".  The reports with properties work correctly with Cassini.

Here's the significant sections from the ASPX page.

 

Page_Load(...)

{

      CrystalReportViewer1.ParameterFieldInfo = newParameterFields();

      CrystalReportViewer1.ParameterFieldInfo.Add(CompleteParameter("week", parameterValue));

     SetDatabaseLogonForReport();

...

}

privateParameterField CompleteParameter(string parmname, object parmvalue)

{

     ParameterDiscreteValue pdv1 = newParameterDiscreteValue();

      pdv1.Value = parmvalue;

      CrystalDecisions.Shared.ParameterValues pv1 = newParameterValues();

      pv1.Add(pdv1);

      CrystalDecisions.Shared.ParameterField pf1 = newParameterField();

      pf1.Name = parmname;

      pf1.CurrentValues = pv1;

     return pf1;

}

 

privatevoid SetDBLogonForReport()

{

     ConnectionInfo c = newConnectionInfo();

     c.ServerName = ".\\SQLEXPRESS";

      c.IntegratedSecurity = true;

     c.DatabaseName = "TheDatabase";

      c.Type = ConnectionInfoType.SQL;

     try

      {

          Tables ts = CrystalReportSource1.ReportDocument.Database.Tables;

          foreach (CrystalDecisions.CrystalReports.Engine.Table t in ts)

           {

               TableLogOnInfo tloi = t.LogOnInfo;

                tloi.ConnectionInfo = c;

                t.ApplyLogOnInfo(tloi);

           }

          foreach (Section s in CrystalReportSource1.ReportDocument.ReportDefinition.Sections)

           {

               // loop through all the report objects to find all the subreports

               foreach (ReportObject ro in s.ReportObjects)

                {

                    if (ro.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)

                     {

                         // you will need to typecast the reportobject to a subreport object once you find it

                          CrystalDecisions.CrystalReports.Engine.SubreportObject sro = (CrystalDecisions.CrystalReports.Engine.SubreportObject)ro;

 

                         // open the subreport object

                          CrystalDecisions.CrystalReports.Engine.ReportDocument subdoc = sro.OpenSubreport(sro.SubreportName);

 

                         // loop through all the tables in the subreport, and apply the connection setup

                         foreach (CrystalDecisions.CrystalReports.Engine.Table t in subdoc.Database.Tables)

                          {

                              t.LogOnInfo.ConnectionInfo = c;

                               t.ApplyLogOnInfo(t.LogOnInfo);

                          }

                     }

                }

           }

      }

     catch (Exception ex)

      {

 

      }

}


Viewing all articles
Browse latest Browse all 3636

Trending Articles