Skip to Content
0
May 22, 2020 at 03:33 PM

Database logon prompt on 2nd page everytime

554 Views

Hello guys

I'm having a strange problem, database logon prompt appears only on the 2nd page (Navigation next page). I am using Visual Studio 2019 community edition and Crystal Reports 13, update 27 that supports VS2019. I don't have this particular problem while reports are made against tables, but stored procedures those accept multiple parameters & the select within the procedure is referring multiple views. To make it easier to understand:

  1. I have two databases
  2. production & test
  3. "sa" has full access on both databases
  4. The views/procedures for reports are created on test database
  5. I don't have any issues while designing the report and reviewing within the IDE. The logon prompt only appears during debugging and post publishing.

The report is being called like below

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ReportDocument reportDocument = new ReportDocument();
                reportDocument.Load(Server.MapPath(@"~/CrystalReport2.rpt"));
                reportDocument.SetParameterValue(0, 2020);
                reportDocument.SetParameterValue(1, 1);
                reportDocument.SetParameterValue(2, 3);
                reportDocument.SetParameterValue(3, "1");
                reportDocument.SetParameterValue(4, "1");

                ConnectionInfo connectionInfo = new ConnectionInfo
                {
                    DatabaseName = "test",
                    UserID = "sa",
                    Password = "password",
                    ServerName = "RAJESH-PC"
                };

                SetDBLogonForReport(connectionInfo, reportDocument);
                CrystalReportViewer1.Visible = true;
                CrystalReportViewer1.ReportSource = reportDocument;
            }
        }

and the SetDBLogonForReport method as below:

 private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument rpt)
        {
            foreach (ReportDocument subRpt in rpt.Subreports)
            {
                foreach (Table crTable in subRpt.Database.Tables)
                {
                    Response.Write(crTable.Name);
                    crTable.LogOnInfo.ConnectionInfo.AllowCustomConnection = true;
                    TableLogOnInfo logInfo = crTable.LogOnInfo;
                    logInfo.ConnectionInfo = connectionInfo;
                    try
                    {
                        crTable.ApplyLogOnInfo(logInfo);
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }
            }

            foreach (Table crTable in rpt.Database.Tables)
            {
                Response.Write(crTable.Name);
                crTable.LogOnInfo.ConnectionInfo.AllowCustomConnection = true;
                TableLogOnInfo loi = crTable.LogOnInfo;
                loi.ConnectionInfo = connectionInfo;
                try
                {
                    crTable.ApplyLogOnInfo(loi);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }

While single page reports are executed without the database logon prompting, I am kind of totally lost after 2 days of continuous efforts to find a solution, Please help.

regards,

rajesh