在MVC应用程序中工作的生产数据库上获取现有Crystal Report的步骤

本文关键字:获取 Crystal Report 数据库 应用程序 MVC 工作 | 更新日期: 2024-09-21 23:44:33

我是Crystal Reports的新手,我发现了很多关于在VS 2010中创建新Crystal Report的文章,但没有关于获取现有报告并使用它生成用户可以导出的PDF的文章。

这是我发现的一篇文章,我试图以此为起点:ASP.NET MVC 中的Crystal报表

当我在ERP系统中运行原始报表时,我运行了SQL Profiler,并试图将此查询用作DataSource,但每次我加载报表文件时,它都会抛出一个异常:

    Exception Details: System.Runtime.InteropServices.COMException: Database logon failed.

如果我通过代码进行调试,HasRecords

    '((CrystalDecisions.CrystalReports.Engine.ReportDocument)(rptH)).HasRecords' threw an exception of type 'CrystalDecisions.CrystalReports.Engine.LogOnException'

我还尝试添加SetDatabaseLogin方法,该方法使用具有DBO访问数据库权限的用户名和密码,但得到了相同的结果。

    rptH.SetDatabaseLogon("username", "password");

因此,长话短说,我想知道是否有人知道一篇好文章,或者可以给我一些万无一失的步骤,让报告在我的代码中工作,在那里我可以返回PDF(即使我先硬编码SQL……我只想看到它工作)。

谢谢!

在MVC应用程序中工作的生产数据库上获取现有Crystal Report的步骤

以下是我们在我工作的地方如何做到这一点的一个过于简化的版本。。。

protected void btnGetReport_Click(object sender, EventArgs e)
{
   System.Guid desiredGuid = System.Guid.NewGuid();
   desiredGuid = createReport();
   //open report in browser
   Response.Redirect(@"SecureReports'" + desiredGuid + ".pdf");
}
private System.Guid createReport()
{
    System.Guid desiredGuid = System.Guid.NewGuid();
    string workpath = "";
    ReportDocument reportDocument = new ReportDocument();
    workpath = @"c:'Reports'cr_myReport.rpt";
    reportDocument.FileName = workpath;
    reportDocument.SetDatabaseLogon("user", "pass", "SERVER''sql", "database");
    reportDocument.SetParameterValue("@param", strParam);
//export CR to a pdf on the server
    reportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, @"c:'SecureReports'" + desiredGuid + ".pdf");
//send location of pdf back to calling function
        return desiredGuid;
    }