Crystal Report转换为PDF(错误登录到数据库失败。((0x8004100f)))

时间:2012-09-06 13:48:43

标签: asp.net vb.net crystal-reports

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

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

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

1 个答案:

答案 0 :(得分: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")