0

我在 Visual Studio 2010 中编写了以下内容:

    label2.Text = Convert.ToString(BAssistencia.nroo);
    ReportDocument oRep = new ReportDocument();
    ParameterField campo = new ParameterField();
    ParameterFields campo2 = new ParameterFields();
    ParameterDiscreteValue Pdv = new ParameterDiscreteValue();

    campo.Name = "@pedido";
    Pdv.Value = label2.Text;
    campo.CurrentValues.Add(Pdv);
    campo2.Add(campo);
    crystalReportViewer1.ParameterFieldInfo = campo2;
    oRep.Load("C:/Relatorios/CrystalReport3.rpt");
    crystalReportViewer1.ReportSource = oRep;
    oRep.SetDatabaseLogon("sa","password","server","database");

该报告可以在装有 Visual Studio 的计算机上正常打开,但是当我部署时,应用程序会一次又一次地询问日志。我究竟做错了什么?提前致谢。

4

2 回答 2

1

您有两种选择来解决这个问题。

  1. 使用 windows 用户帐户访问数据库 更多详细信息在这里

  2. 将凭据动态应用于主报告和所有子报告

将 DB 日志记录信息应用于每个 Crystal Reports 部分时,应用程序运行缓慢

http://www.daniweb.com/software-development/csharp/threads/214322/c-crystal-reports-sharing-database-and-server-name

于 2012-07-02T07:36:24.300 回答
0

你能试试这个代码吗

ReportDocument rpt = new ReportDocument();
        rpt.Load(@"C:\CrystalReport1.rpt");

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "SERVERNAME";
        crConnectionInfo.DatabaseName = "DATABASENAME";
        crConnectionInfo.UserID = "USERNAME";
        crConnectionInfo.Password = "PASSWORD";
        crConnectionInfo.IntegratedSecurity = false;

        TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
        TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
        Tables CrTables;
        CrTables = rpt.Database.Tables;

        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in CrTables)
        {
            crTableLogonInfo = crTable.LogOnInfo;
            crTableLogonInfo.ConnectionInfo = crConnectionInfo;
            crTable.ApplyLogOnInfo(crTableLogonInfo);
        }
        crystalReportViewer1.ReportSource = rpt;
        crystalReportViewer1.Refresh();
于 2012-07-02T07:28:53.350 回答