0

私は Crystal Reports の世界に不慣れで、VS 2010 で新しい Crystal Report を作成することに関するさまざまな記事を見つけましたが、既存のレポートを取得して、それを使用してエクスポートできる PDF を生成することについては何もありませんユーザー。

これは、私が最初に使用しようとしていた記事です: Crystal Reports in ASP.NET MVC

ERP システムで元のレポートを実行しているときに SQL プロファイラーを実行し、このクエリをデータソースとして使用しようとしましたが、レポート ファイルをロードするポイントに到達するたびに例外がスローされます。

    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'

また、データベースへの DBO アクセス権を持つユーザー名とパスワードを使用して SetDatabaseLogin メソッドを追加しようとしましたが、同じ結果が得られました。

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

長い話を長くするために、誰かが良い記事を知っているか、PDF を返すことができるコードでレポートを機能させるための簡単な手順を教えてくれるかどうか疑問に思っています (SQL をハードコードしたとしても)最初...私はそれが機能するのを見たいだけです)。

ありがとう!

4

1 に答える 1

0

これは、私が働いている場所で行う方法の非常に単純化されたバージョンです...

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;
    }
于 2012-08-03T19:57:01.047 に答える