Hi experts,
Our company SAP B1 add-on is providing HANA crystal report templates (as .rpt files) so that one can access the report model and provide database credentials to logon to the report and access it. I have pasted the VB code to do connection to Crystal report from our add-on. And it is working fine, if we are providing database credentials from add-on. But as we switch to Cloud HANA version of B1, single sign on feature is being used to log on to SAP. Here we are expecting that , it should connect to crystal report as well without database credentials since SAP will not provide database credentials in cloud environment. But the problem here is that, we are receiving the error as 'Database logon failed' when trying to do the same. Can you please verify the scenario and advise fine solution for this issue. Do we need to change the structure of using reports. Please help.
-------------------------------------------------------------------------------------------------------------
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Dim c As ConnectionInfo
Dim crDB As Database
Dim crTables As Tables
Dim crTable As Table
Dim TblLogonInfo As TableLogOnInfo
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim subRepDoc As New ReportDocument
Dim ServerName As String, DatabaseName As String
Try
Me.rptDoc.Load(sCRPath, OpenReportMethod.OpenReportByTempCopy)
ServerName = ActiveCompanyName
DatabaseName = ActiveDB
c = New ConnectionInfo
'Set Conenction info for DB
With c
.ServerName = ServerName
.DatabaseName = DatabaseName
.UserID = DatabaseUsername
.Password = DatabasePassword
End With
'Associate DB to the report
crDB = Me.rptDoc.Database
'Instantiate Tables collection
crTables = crDB.Tables
'Loop thru tables in report and set connection information
For Each crTable In Me.rptDoc.Database.Tables
TblLogonInfo = crTable.LogOnInfo
TblLogonInfo.ConnectionInfo = c
crTable.ApplyLogOnInfo(TblLogonInfo)
If Not crTable.Location.Contains(".") Then Continue For
crTable.Location = c.DatabaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
'Set the sections collection with report sections
crSections = Me.rptDoc.ReportDefinition.Sections
'Loop through each section and find all the report objects
'Loop through all the report objects to find all subreport objects, then set the
'logoninfo to the subreport
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
'If you find a subreport, typecast the reportobject to a subreport object
crSubreportObject = CType(crReportObject, SubreportObject)
'Open the subreport
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDB = subRepDoc.Database
crTables = crDB.Tables
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object then apply the
'logoninfo to the subreport
For Each crTable In crTables
With c
.ServerName = ServerName
.DatabaseName = DatabaseName
.UserID = DatabaseUsername
.Password = DatabasePassword
End With
TblLogonInfo = crTable.LogOnInfo
TblLogonInfo.ConnectionInfo = c
crTable.ApplyLogOnInfo(TblLogonInfo)
If Not crTable.Location.Contains(".") Then Continue For
crTable.Location = c.DatabaseName & ".dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
Next
End If
Next
Next
Catch ex As Exception
Throw ex
Finally
subRepDoc.Close()
subRepDoc.Dispose()
End Try
Try
Dim strConnection As String = ""
If (IntPtr.Size = 4) Then ' 32
strConnection += "DRIVER={B1CRHProxy32};UID=" + DatabaseUsername
strConnection += ";PWD=" + DatabasePassword + ";SERVERNODE=" + ServerName
strConnection += ";DATABASE=" + ActiveDB + ";"
Dim logonProps2 As NameValuePairs2 = rptDoc.DataSourceConnections(0).LogonProperties
logonProps2.Set("Provider", "B1CRHProxy32")
logonProps2.Set("Server Type", "B1CRHProxy32")
logonProps2.Set("Connection String", strConnection)
logonProps2.Set("Locale Identifier", "1033")
rptDoc.DataSourceConnections(0).SetLogonProperties(logonProps2)
rptDoc.DataSourceConnections(0).SetConnection(ServerName, ActiveDB, DatabaseUsername, DatabasePassword)
'oErrorLog.WriteLogFile("Finished")
Else
'oErrorLog.WriteLogFile("In SetRport function 64 bit")
strConnection += "DRIVER={B1CRHProxy};UID=" + DatabaseUsername
strConnection += ";PWD=" + DatabasePassword + ";SERVERNODE=" + ServerName
strConnection += ";DATABASE=" + ActiveDB + ";"
'oErrorLog.WriteLogFile(strConnection)
Dim logonProps2 As NameValuePairs2 = rptDoc.DataSourceConnections(0).LogonProperties
logonProps2.Set("Provider", "B1CRHProxy")
logonProps2.Set("Server Type", "B1CRHProxy")
logonProps2.Set("Connection String", strConnection)
logonProps2.Set("Locale Identifier", "1033")
rptDoc.DataSourceConnections(0).SetLogonProperties(logonProps2)
rptDoc.DataSourceConnections(0).SetConnection(ServerName, ActiveDB, DatabaseUsername, DatabasePassword)
'rptDoc.DataSourceConnections(0).SetConnection(ServerName, ActiveDB, True)
'oErrorLog.WriteLogFile("Finished")
End If
Catch ex As Exception
Throw ex
End Try
-------------------------------------------------------------------------------------------------------------
Thanks
JishaSony