当我更改页面时如何避免 crystalreport 询问数据库身份验证

How to avoid crystalreport ask database authentication when i change a page

你好朋友我有一个问题,我有我的报告(.rpt)它显示不错但是当我按下按钮看到以下页面时它要求我提供参数和数据库身份验证,这是我的代码:

cryRpt = new ReportDocument();
try
{
    cryRpt.Load((Application.StartupPath + "\rpExclu.rpt").Replace("\bin\Debug", ""));
    cryRpt.SetParameterValue("@IDA", id);
    cryRpt.SetDatabaseLogon("sa", "password$$$");
    crvReportes.ReportSource = cryRpt;
    crvReportes.Refresh();
}
catch (Exception ex)
{
    crvReportes.Refresh();
    XtraMessageBox.Show("" + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
    cryRpt.Dispose();
    cryRpt.Close();
}

我给你看快照:

提前致谢。

如果您的目标是从 SQL 填充数据,您可以通过 rpt 文件设置连接,方法是在任务栏上选择 数据库 > 数据库专家 > OLE DB (ADO) ( if MS SQL) > SQL Server Native Clinet。以这种方式设置的连接也将在评估报告时使用,因此您无需每次都通过它。

早上好朋友们。我修改了我的代码以避免询问参数。我删除了 cryRpt.Dispose() 和 cryRpt.Close()。它有效,但我决定将这些代码行放在 winform 关闭事件中。我的代码是:

public FrmReport()
{
    InitializeComponent();
    rpDoc = new ReportDocument();
    crvReportes.AllowedExportFormats = (int)(ViewerExportFormats.ExcelFormat | ViewerExportFormats.PdfFormat| ViewerExportFormats.WordFormat);
}
private void LoadReport()
{
    try
    {
        rpDoc.Load((Application.StartupPath + "\rpExclu.rpt").Replace("\bin\Debug", ""));
        rpDoc.SetParameterValue("@IDA", this.ida);
        rpDoc.SetDatabaseLogon(this.us, this.pass);
        crvReportes.ReportSource = rpDoc;
        crvReportes.Refresh();
    }
    catch (Exception ex)
    {
        crvReportes.Refresh();
        XtraMessageBox.Show("" + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
private void FrmReporteBienes_FormClosing(object sender, FormClosingEventArgs e)
{
    if (rpDoc.IsLoaded)
    {
        rpDoc.Dispose();
        rpDoc.Close();
    }
}

这是最好的解决方案吗?好吧,在这一刻它起作用了。提前致谢。