Search code examples
c#.netwinformscrystal-reports

crystal report with sub reports not working on production/test machine C# winforms


I have created crystal report with 8 sub-reports (using VS 2010). I have created stored proc which populates all the dump SQL server tables which are linked to main report & sub reports. My code is working fine on development machine but when same is deployed to another machine it throws following error.

Failed to Open the connection.
Details : [Database vendor code 17]
Failed to Open the connection.
rpt_reportName{GUID}.rpt
Details : [Database vendor code 17]

following is my code to generate report.

ReportDocument crReportDocument;
        Boolean TypesDSReports = false;
        clsErrorLog oLog = new clsErrorLog();

        static TableLogOnInfo crTableLogonInfo;
        static ConnectionInfo crConnectionInfo;
        static Tables crTables;
        static Database crDatabase;
 public static void ReportLogin(ReportDocument crDoc, string Server, string Database, string UserID, string Password)
        {
            crConnectionInfo = new ConnectionInfo();
            crConnectionInfo.ServerName = Server;
            crConnectionInfo.DatabaseName = Database;
            crConnectionInfo.UserID = UserID;
            crConnectionInfo.Password = Password;
            crDatabase = crDoc.Database;
            crTables = crDatabase.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
            {
                crTableLogonInfo = crTable.LogOnInfo;
                crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogonInfo);
            }

            //crDoc.Subreports["aa"].co = crConnectionInfo;

        }




private void DisplayReportWithSubReport()
        {
            try
            {
                ReportDocument crReportDocument = new ReportDocument();
                crReportDocument.Load(sReportPath.Trim());

                ReportLogin(crReportDocument, clsCustomize.gsPropServerName, clsCustomize.gsPropCurrentDataBaseName, clsCustomize.gsPropDataBaseUserID, clsCustomize.gsPropDataBasePassword);
                crReportDocument.Refresh();
                CRViewer.ReportSource = crReportDocument;
                CRViewer.RefreshReport();
                this.Text = sDisplayReportCaption;

                if (TypesDSReports == false)
                {
                    crReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
                }
                this.WindowState = FormWindowState.Maximized;

                if (HMS.Common.clsConstants.gbPropCloseReportForm == true)
                {

                    crReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
                    if (HMS.clsCustomize.giNoOfPrintCopies == 0)
                    {
                        HMS.clsCustomize.giNoOfPrintCopies = 1;
                    }

                    crReportDocument.PrintToPrinter(HMS.clsCustomize.giNoOfPrintCopies, false, 1, 1);
                    HMS.Common.clsConstants.gbPropCloseReportForm = false; //Reset the Flag
                    this.Close();
                }
                else
                {
                    this.WindowState = FormWindowState.Maximized;
                }
            }
            catch (Exception ex)
            {
                oLog.LogError(ex, "", "", "", "");
            }


        }

Dev machine and target machine both have same system configuration.Kindly help where is the issue?

Regards, Vikram


Solution

  • I figured out solution myself. I added following code in the ReportLogin method and it worked perfectly.

     for (int i = 0; i < crDoc.Subreports.Count; i++)
                    {
                        crDoc.Subreports[i].SetDatabaseLogon(UserID, Password, Server, Database);
                    }