0

在我的应用程序中,我有一些代码可以转换为 PDF。在调试模式下,一切都很好并且可以正常工作,但是当我在服务器上对其进行测试时,我不断登录到数据库失败。我不知道为什么我会收到错误,因为登录名和密码都是 100% 好的。

为发送报告的服务器尝试了 2 种方法

SetCrystalReportFilePath(Server.MapPath("~/MemberPages/Report.rpt"))
SetPdfDestinationFilePath(Server.MapPath("~/MemberPages/Report_" & Report & ".pdf"))
SetRecordSelectionFormula("{Report.Report_id} =" & ID)
Transfer()



SetCrystalReportFilePath("C:\inetpub\wwwroot\Werkbon.rpt")
SetPdfDestinationFilePath("C:\inetpub\wwwroot\Werkbon_" & werkbonnr & ".pdf")
SetRecordSelectionFormula("{werkbon.werkbon_id} =" & werkbonnr)
Transfer()

Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim oRDoc As New ReportDocument
Dim expo As New ExportOptions
Dim sRecSelFormula As String
Dim oDfDopt As New DiskFileDestinationOptions
Dim strCrystalReportFilePath As String
Dim strPdfFileDestinationPath As String

Public Function SetCrystalReportFilePath(ByVal CrystalReportFileNameFullPath As String)
    strCrystalReportFilePath = CrystalReportFileNameFullPath
End Function

Public Function SetPdfDestinationFilePath(ByVal pdfFileNameFullPath As String)
    strPdfFileDestinationPath = pdfFileNameFullPath
End Function

Public Function SetRecordSelectionFormula(ByVal recSelFormula As String)
    sRecSelFormula = recSelFormula
End Function

Public Function Transfer()
    oRDoc.Load(strCrystalReportFilePath)
    oRDoc.RecordSelectionFormula = sRecSelFormula
    oDfDopt.DiskFileName = strPdfFileDestinationPath
    expo = oRDoc.ExportOptions
    expo.ExportDestinationType = ExportDestinationType.DiskFile
    expo.ExportFormatType = ExportFormatType.PortableDocFormat
    expo.DestinationOptions = oDfDopt
    oRDoc.SetDatabaseLogon("databasename", "password")
    oRDoc.Export()
End Function
4

1 回答 1

0

Crystal 在交换连接信息时非常特别(尤其是在有子报告时)。多年来,他们并没有真正变得更好,这一直是一个痛处。我分享了一个博客条目,其中包含我创建的扩展方法(在 VB.Net 中),以便轻松加载和交换新连接(通常我使用 ADO 作为报告中的连接)。可以在此链接中找到扩展方法(下面是如何使用它们的示例,如果您从 ASP.NET 使用它,请忽略 System.Diagnostics 行)。希望这可以帮助。

http://www.blakepell.com/Blog/?p=487

    Using rd As New ReportDocument
        rd.Load("C:\Temp\CrystalReports\InternalAccountReport.rpt")
        rd.ApplyNewServer("serverName or DSN", "databaseUsername", "databasePassword")
        rd.ApplyParameters("AccountNumber=038PQRX922;", True)
        rd.ExportToDisk(ExportFormatType.PortableDocFormat, "c:\temp\test.pdf")
        rd.Close()
    End Using

    System.Diagnostics.Process.Start("c:\temp\test.pdf")
于 2012-09-06T15:01:35.253 回答