SAP Knowledge Base Article - Public

1372523 - How to get database connection properties associated with a Crystal report using Visual Studio .NET?

Symptom

  • It is often useful for an application developer to be able to determine which database connection properties are used by a report.

Resolution

  • The connection properties associated with a report can be retrieved by using the following code in Visual Studio .NET.
Dim msg As String
Dim crTable As Table   
Dim crLogOnInfo As TableLogOnInfo  
Dim crConnectionInfo As ConnectionInfo  
Dim i As Integer
Dim crReportDocument as New CrystalDecisions.CrystalReports.Engine.ReportDocument
msg = ""
crReportDocument .Load(Application.StartupPath & "\<report name>")
For Each crTable In crReportDocument.Database.Tables
            crLogOnInfo  = crTable.LogOnInfo
            crConnectionInfo = crLogOnInfo.ConnectionInfo
            For i = 0 To crConnectionInfo.Attributes.Collection.Count - 1
                If TypeOf (CType(crConnectionInfo .Attributes.Collection(i), NameValuePair2).Value) Is CrystalDecisions.Shared.DbConnectionAttributes Then
                    msg = msg & Environment.NewLine
                    Dim j As Integer
                    Dim nvs2 As NameValuePairs2
                    nvs2 = CType(CType(crConnectionInfo.Attributes.Collection(i), NameValuePair2).Value, CrystalDecisions.Shared.DbConnectionAttributes).Collection
                    For j = 0 To nvs2.Count - 1
                        msg = msg & "DCA Attribute:  " & CType(nvs2(j), CrystalDecisions.Shared.NameValuePair2).Name & " - "
                        msg = msg & CType(nvs2(j), CrystalDecisions.Shared.NameValuePair2).Value & Environment.NewLine
                    Next
                    msg = msg & Environment.NewLine
                Else
                    msg = msg & CType(crConnectionInfo.Attributes.Collection(i), NameValuePair2).Name & " - "
                    msg = msg & CType(crConnectionInfo.Attributes.Collection(i), NameValuePair2).Value & Environment.NewLine
                End If
            Next
Next
MessageBox.Show(msg)

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, developer version for Microsoft Visual Studio