1

我无法将此报告导出为 pdf。我以前做过很多次,但现在我碰壁了。任何帮助,将不胜感激。

这是在 Windows 7 64 位机器上。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

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

Source Error: 



Line 25:         exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
Line 26:         exportOpts.ExportFormatOptions = pdfOpts
Line 27:         report.ExportToHttpResponse(exportOpts, Response, False, "")
Line 28: 
Line 29:     End Sub

Stack Trace: 



[COMException (0x8004100f): Database logon failed.]
   CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +519

[LogOnException: Database logon failed.]
   CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +1243
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +621
   CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +1201
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) +150
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName) +212
   reports_CreateReport.generateReport(DataSet ds, String reportpath, ArrayList params) in C:\Users\boruch\Dropbox\Korns-ConnectionStr\reports\CreateReport.aspx.vb:27
   reports_CreateReport.btn_GenReport_Click(Object sender, EventArgs e) in C:\Users\boruch\Dropbox\Korns-ConnectionStr\reports\CreateReport.aspx.vb:58
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9552602
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044 
4

2 回答 2

3

我将继续发布我所拥有的内容,以便它可能对您有所帮助。我们放弃了 Crystal,因为它太粗略了(我相信第一次导出会失败,然后每次都会工作,直到应用程序关闭),SAP 基本上告诉我们他们不在乎我们是否采取了远足,所以我们做到了。我们切换到 SSRS 并为此感到高兴得多……但我离题了。

你没有显示很多代码,所以我不知道这是否是你的工作方式。另外,我的是 C#,所以你需要转换......但希望你能在这个例子的某个地方找到你的问题的解决方案。我想它将在凭据的设置中...

加载文档:

ReportDocument rd = new ReportDocument();
rd.Load(rptFile);

设置凭据

ConnectionInfo connectInfo = new ConnectionInfo()
{
    ServerName = dbServer,
    DatabaseName = "",
    UserID = userId,
    Password = password
};
rd.SetDatabaseLogon(userId, password);
foreach (Table tbl in rd.Database.Tables)
{
    tbl.LogOnInfo.ConnectionInfo = connectInfo;
    tbl.ApplyLogOnInfo(tbl.LogOnInfo);
}

然后设置导出:

DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
ExportOptions CrExportOptions;
PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = outputPath;
CrExportOptions = rd.ExportOptions;
{
    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
    CrExportOptions.FormatOptions = pdfFormatOptions;
}

供应报告参数

SetCurrentValuesForParameterField(rd, "IP_COMP_CODE", cc);
SetCurrentValuesForParameterField(rd, "IP_YEAR", yr);
SetCurrentValuesForParameterField(rd, "IP_WEEK", wk);

和出口...

rd.Export();

SetCurrentValuesForParameterField 的实现:

private void SetCurrentValuesForParameterField(ReportDocument reportDocument, string paramFieldName, int value)
{
    ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
    parameterDiscreteValue.Value = value;

    ParameterValues currentParameterValues = new ParameterValues();
    currentParameterValues.Add(parameterDiscreteValue);

    reportDocument.DataDefinition.ParameterFields[paramFieldName].ApplyCurrentValues(currentParameterValues);
}
于 2013-07-09T20:50:33.480 回答
0

我也遇到了这个错误。我已经通过检查我的数据表值来解决它。我错过了对一个数据表进行查询。

例如:我的 Crystal 报表数据集中有 11 个数据表。但我想查询数据表 11。在我签出并更正它之后。现在我的 excel 和 PDf 工作正常,没有数据库登录失败错误..

希望它对你有用...

于 2016-04-11T05:41:51.800 回答