1

这是登录信息方法

private void SetLogonInfo()
    {
        try
        {
            LogInfo.ConnectionInfo.ServerName = "ServerName";
            LogInfo.ConnectionInfo.UserID = "UserID";
            LogInfo.ConnectionInfo.Password = "Password";
            LogInfo.ConnectionInfo.DatabaseName = "DataBase";
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

要创建报告,我使用了此代码

            crystalReportViewer1.ReportSource = null;
            rptdoc = new ReportDocument();
            rptdoc.Load("REPORTS\\TC.rpt");
            crystalReportViewer1.SelectionFormula =selectionFormula;
            crystalReportViewer1.ReportSource = rptdoc;
            rptdoc.Database.Tables[0].ApplyLogOnInfo(LogInfo);

它在服务器系统中运行良好,但如果我在客户端系统中使用它,它会要求输入用户名和密码。我正在使用 Crystal Reports 10。此外,有时它还会在服务器系统中询问用户名密码。如何解决这个问题?

4

2 回答 2

1

你做事的顺序不对。在将报告加载到查看器之前,您需要以编程方式登录。

此外,我不能强调您需要在服务器机器和测试客户端机器上测试您的程序,然后再将其发布给用户。

于 2012-07-26T14:27:45.227 回答
0

此错误的原因是用户名、密码错误。
检查用户名、密码并使用以下代码:

ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

//This is for Access Database
crConnectionInfo.ServerName = "" + "" +Application.StartupPath + "\\Database.mdb"; //access Db Path
crConnectionInfo.DatabaseName = "" + "" + Application.StartupPath + "\\Database.mdb";//access Db Path
crConnectionInfo.UserID = "ADMIN";
crConnectionInfo.Password = Program.DBPassword; //access password

//This is for Sql Server
crConnectionInfo.UserID = Program.Severuser; //username
crConnectionInfo.Password = Program.Password;//password
crConnectionInfo.ServerName = Program.server;//servername
crConnectionInfo.DatabaseName = Program.database;//database

string path = "" + Application.StartupPath + "\\supportingfiles\\Invoice.rpt";
cryRpt.Load(path);
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
   crtableLogoninfo = CrTable.LogOnInfo;
   crtableLogoninfo.ConnectionInfo = crConnectionInfo;
   CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

cryRpt.SetParameterValue("invoiceno", Program.billno);

crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
于 2018-01-20T17:16:11.943 回答