数据库登录提示用水晶报表 [英] database login prompt with crystal reports

查看:115
本文介绍了数据库登录提示用水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 私人无效frmReporte_Load(对象发件人,发送System.EventArgs)
    {
        来福= ConfigurationSettings.AppSettings [密码]的ToString()。
        NombreBD = ConfigurationSettings.AppSettings [CatalogBD]的ToString()。
        NombreServidor = ConfigurationSettings.AppSettings [Servidor]的ToString()。 ;
        UsuarioBD = ConfigurationSettings.AppSettings [用户名]的ToString()。
        。this.crtReportes.ReportSource =这个prepareReport();
    }
    公共无效imprimirReporte()
    {
        的ReportDocument RPT =新的ReportDocument();
        rpt.Load(mvarRutaReporte);
        rpt.SetDataSource(clsReportes.dsReporte);
        rpt.PrintToPrinter(1,假,1,1);
    }
    私人的ReportDocument prepareReport()
    {
        第crSections;
        的ReportDocument crReportDocument,crSubreportDocument;
        SubreportObject crSubreportObject;
        ReportObjects crReportObjects;
        ConnectionInfo crConnectionInfo;
        数据库crDatabase;
        表crTables;
        TableLogOnInfo crTableLogOnInfo;
        crReportDocument =新的ReportDocument();
        crReportDocument.Load(RutaReporte);
        crReportDocument.SetDataSource(clsReportes.dsReporte.Tables [0]);
        crDatabase = crReportDocument.Database;
        crTables = crDatabase.Tables;
        crConnectionInfo =新ConnectionInfo();
        crConnectionInfo.ServerName = NombreServidor;
        crConnectionInfo.DatabaseName = NombreBD;
        crConnectionInfo.UserID = UsuarioBD;
        crConnectionInfo.Password =来福;
        的foreach(CrystalDecisions.CrystalReports.Engine.Table aTable在crTables)
        {
            crTableLogOnInfo = aTable.LogOnInfo;
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
            aTable.ApplyLogOnInfo(crTableLogOnInfo);
        }
        //帕拉洛杉矶reportes阙poseen subreportes
        //猩猩报objeto seccion德尔拉seccion实际德尔reporte
        crSections = crReportDocument.ReportDefinition.Sections;
        //我正在寻找恩托达拉斯secciones埃尔objeto reporte
        的foreach(在crSections节crSection)
        {
            crReportObjects = crSection.ReportObjects;
            //我正在寻找连接待办事项洛杉矶reportes POR subreportes
            的foreach(ReportObject crReportObject在crReportObjects)
            {
                如果(crReportObject.Kind == ReportObjectKind.SubreportObject)
                {
                    crSubreportObject =(SubreportObject)crReportObject;
                    //爱宝埃尔subreporteŸ我logeo CON洛杉矶DATOS德尔reporte一般
                    crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
                    crDatabase = crSubreportDocument.Database;
                    crTables = crDatabase.Tables;
                    的foreach(CrystalDecisions.CrystalReports.Engine.Table aTable在crTables)
                    {
                        crTableLogOnInfo = aTable.LogOnInfo;
                        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                        aTable.ApplyLogOnInfo(crTableLogOnInfo);
                    }
                }
            }
        }
        返回crReportDocument;
    }
 

解决方案

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

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

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

I'm trying to display some report with some subreports inside it, but every it shows the report it throws some dialog box asking for database connection. I'm using this code:

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;
    }

解决方案

I had a similar problem and it is solved now, so I'm adding this reply in case it might help someone else in my situation.

When setting the SQL Server login info for the report, make sure you include the service name. So, for example, make sure you're giving Crystal "myserver\myservice" instead of just "myserver".

My program is able to access data from SQL Server using just "myserver", but Crystal needs to be given "myserver\myservice".

这篇关于数据库登录提示用水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆