如何从HANA DB渲染Crystal Report

时间:2018-07-09 12:08:36

标签: vb.net crystal-reports hana

我有一个使用Microsoft SQL多年的例程,但是现在它需要使用HANA DB。我已经用我能找到的任何示例重写了很多次代码,但是我仍然得到Engine.InternalException“无法打开连接”。同一台机器上的Crystal报表设计器可以打开报表。这是我的代码:

Public Sub SaveCrystalReport(ByVal RptFilename As String, ByVal ReportParameters As Hashtable, SaveAsPDFFileName As String)
    Trace.TraceInformation("PrintCrystalReport(): " & RptFilename)

    Using cdoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Trace.TraceInformation("Loading report: " & RptFilename)
        cdoc.Load(RptFilename)

        For Each paramKey As CrystalDecisions.Shared.ParameterField In cdoc.ParameterFields
            Trace.TraceInformation("Report has parameter: " & paramKey.Name)

            If ReportParameters.ContainsKey(paramKey.Name) Then
                Trace.TraceInformation("Print request has parameter " & paramKey.Name & ", setting it.")
                Try
                    Dim rptparam As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = cdoc.DataDefinition.ParameterFields.Item(paramKey.Name)
                    If rptparam IsNot Nothing AndAlso Not rptparam.IsLinked Then
                        cdoc.SetParameterValue(paramKey.Name, ReportParameters.Item(paramKey.Name))
                    End If
                Catch pex As Exception
                    Trace.TraceError("Failed to set parameter in crystal report: " & paramKey.Name & vbCrLf & pex.ToString)
                End Try
            End If
        Next

        Dim ci As New CrystalDecisions.Shared.ConnectionInfo

        ci.AllowCustomConnection = True

        ci.UserID = CompanySQLUser
        ci.Password = CompanySQLPass
        ci.ServerName = CompanySQLServer
        ci.DatabaseName = CompanyDatabase

        ci.LogonProperties.Clear()
        ci.LogonProperties.Add(New NameValuePair2("ConnectionString", ci.ServerName))
        ci.LogonProperties.Add(New NameValuePair2("UseDSNProperties", False))

        'cdoc.SetDatabaseLogon(CompanySQLUser, CompanySQLPass, CompanySQLServer, CompanyDatabase)
        cdoc.SetDatabaseLogon(CompanySQLUser, CompanySQLPass)

        For Each tbl As CrystalDecisions.CrystalReports.Engine.Table In cdoc.Database.Tables

            Dim logon As CrystalDecisions.Shared.TableLogOnInfo = tbl.LogOnInfo
            logon.ConnectionInfo = ci
            tbl.ApplyLogOnInfo(logon)
        Next

        cdoc.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, SaveAsPDFFileName)
    End Using
End Sub

我正在传递DBName,用户名和密码,但是对于服务器,我正在传递形式为“ DRIVER = {B1CRHPROXY}; SERVERNODE = ...; DATABASE = ...”的ODBC连接字符串以及我的数据库设置匹配我的连接字符串中的一个。在内部,该报告使用的是ConnectionInfoType CRQE,我认为这对于ODBC样式连接是正确的。

我还尝试了此操作,但未应用任何连接信息(用户名和密码除外),我认为这些信息会从封装在报告文件中的数据库中呈现报告,但这也不起作用。

有人知道我在做什么错吗-naaybody在由HANA数据库支持时是否能够通过API渲染Crystal?

谢谢

0 个答案:

没有答案