与晶体的报告数据库登录提示(database login prompt with crystal r

2019-06-26 01:01发布

我想展示一些报告 ,里面的一些子报表 ,但每次它表明它抛出一些对话框,询问数据库连接的报告。 我使用此代码:

private void frmReporte_Load(object sender, System.EventArgs e)
    {
        Clave = ConfigurationSettings.AppSettings["Password"].ToString();
        NombreBD = ConfigurationSettings.AppSettings["CatalogBD"].ToString();
        NombreServidor = ConfigurationSettings.AppSettings["Servidor"].ToString(); ;
        UsuarioBD = ConfigurationSettings.AppSettings["UserID"].ToString();
        this.crtReportes.ReportSource = this.prepareReport();
    }
    public void imprimirReporte()
    {
        ReportDocument rpt = new ReportDocument();
        rpt.Load(mvarRutaReporte);
        rpt.SetDataSource(clsReportes.dsReporte);
        rpt.PrintToPrinter(1, false, 1, 1);
    }
    private ReportDocument prepareReport()
    {
        Sections crSections;
        ReportDocument crReportDocument, crSubreportDocument;
        SubreportObject crSubreportObject;
        ReportObjects crReportObjects;
        ConnectionInfo crConnectionInfo;
        Database crDatabase;
        Tables crTables;
        TableLogOnInfo crTableLogOnInfo;
        crReportDocument = new ReportDocument();
        crReportDocument.Load(RutaReporte);
        crReportDocument.SetDataSource(clsReportes.dsReporte.Tables[0]);
        crDatabase = crReportDocument.Database;
        crTables = crDatabase.Tables;
        crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = NombreServidor ;
        crConnectionInfo.DatabaseName = NombreBD;
        crConnectionInfo.UserID = UsuarioBD;
        crConnectionInfo.Password = Clave;
        foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
        {
            crTableLogOnInfo = aTable.LogOnInfo;
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
            aTable.ApplyLogOnInfo(crTableLogOnInfo);
        }
        // Para los reportes que poseen subreportes 
        // pongo el objeto seccion del la seccion actual del reporte 
        crSections = crReportDocument.ReportDefinition.Sections;
        // busco en todas las secciones el objeto reporte
        foreach (Section crSection in crSections)
        {
            crReportObjects = crSection.ReportObjects;
            //busco en todos los reportes por subreportes
            foreach (ReportObject crReportObject in crReportObjects)
            {
                if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    crSubreportObject = (SubreportObject)crReportObject;
                    //abro el subreporte y me logeo con los datos del reporte general
                    crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
                    crDatabase = crSubreportDocument.Database;
                    crTables = crDatabase.Tables;
                    foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
                    {
                        crTableLogOnInfo = aTable.LogOnInfo;
                        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                        aTable.ApplyLogOnInfo(crTableLogOnInfo);
                    }
                }
            }
        }
        return crReportDocument;
    }

Answer 1:

我有一个类似的问题,现在解决了,所以我的情况下,加入这个答复可能帮助别人在我的情况别的。

当设置报表的SQL Server登录信息,请确保您有服务名称。 因此,例如,要确保你给水晶“MYSERVER \的MyService”,而不仅仅是“MYSERVER”。

我的计划是能够访问使用只是“MYSERVER”从SQL Server的数据,但水晶需要给予“MYSERVER \为MyService”。



Answer 2:

在水晶,你可以指定是否提示分贝登录@报告生成的Crystal管理控制台(CMC)@每个报告水平的时间。 登录CMC,打开您的报告>过程>数据库。 在页面的底部,你可以指定“提示输入数据库登录用户”,“数据库登录使用SSO上下文”或“使用相同的数据库登录时运行报告为”。 选择使用存储在服务器的凭据的第三个选项。



Answer 3:

你可以只写report.SetDatabaseLogon( “用户名”, “PWD”,@ “服务器”, “数据库”); 给出的登录信息,然后数据库登录框时将运行的代码将不会出现。



文章来源: database login prompt with crystal reports