How to stop crystal report viewer from asking login credentials when opening subreport

The problem is in Crystal Report login info. before showing the report you have to set login info to all tables which are included in main report and their sub reports. You are using Disconnected Datasource Report Show method. so you don’t need to provide login info to report document. your problem is here.

report.SetDataSource(ds);

when you are using SetDataSource method it is necessary to provide all tables which are included in crystal report document. here, you have passed only a single table in dataset. you must pass all tables including subreport tables.

I am suggesting you if you are using subreport then use connected datasource method instead if disconnected datasource(report.SetDataSource()). in Connected datasource you have to set login info before showing the report.

private void PrintReport()
    {

        ReportDocument report = new ReportDocument();
        report.Load("ReportPath");

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "HPL-WTS";
        crConnectionInfo.DatabaseName = "Enterprise32";
        crConnectionInfo.UserID = "sa";
        crConnectionInfo.Password = "*********";
        TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();

        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in report.Database.Tables)
        {
            crTableLogoninfo = CrTable.LogOnInfo;
            crTableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crTableLogoninfo);
        }
        foreach (ReportDocument subreport in report.Subreports)
        {
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in subreport.Database.Tables)
            {
                crTableLogoninfo = CrTable.LogOnInfo;
                crTableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crTableLogoninfo);
            }
        }                         

        CrystalReportViewer1.ReportSource = report;

        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
    }

if you want to use disconnected datasource even you have not included subreport then you can use a single command instead of multiple tables. that will make easy and gives better performance. becuase you just need to pass only a single table into SetDataSource method. but, dont forget to set tablename in DataTable otherwise report will not be displayed.

Leave a Comment