Quantcast
Viewing all articles
Browse latest Browse all 3636

Crystal Reports in deployed environment Logon Failed

I have read about every blog and tried every solution but to no avail.  This is my code:

 

Imports Microsoft.VisualBasic

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

 

 

Public Class cReportSetup

    Dim crtableLogoninfos As New TableLogOnInfos()

    Dim crtableLogoninfo As New TableLogOnInfo()

    Dim crConnectionInfo As New ConnectionInfo()

    Dim CrTables As Tables

    Dim CrTable As Table

    Dim TableCounter

    Dim o As New aspdata.cData

    Dim boMainPropertyBag As New DbConnectionAttributes()

    Dim boInnerPropertyBag As New DbConnectionAttributes()

 

 

    Public Function configureCR(ByRef reportName As String) As ReportDocument

        With crConnectionInfo

            If o.dbInstance Is Nothing Or o.dbInstance.Length = 0 Then

                .ServerName = o.dbServer & o.dbPort

            Else

                .ServerName = o.dbServer & "\" & o.dbInstance & o.dbPort

            End If

 

 

            .DatabaseName = "ASP"

            .UserID = o.dbUser

            .Password = o.dbPassword

            .IntegratedSecurity = False

            .Type = ConnectionInfoType.SQL

            .AllowCustomConnection = True

        End With

 

 

 

 

        'Set the attributes for the boInnerPropertyBag

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Auto Translate", "-1"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Connect Timeout", "15"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Data Source", crConnectionInfo.ServerName))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("DataTypeCompatibility", "0"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("General Timeout", "0"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Initial Catalog", "ASP"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Integrated Security", "False"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Locale Identifier", "1033"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("MARS Connection", "0"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("OLE DB Services", "-5"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Provider", "SQLNCLI10"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Tag with column collation when possible", "0"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Trust Server Certificate", "0"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Use DSN Default Properties", "False"))

        boInnerPropertyBag.Collection.Add(New NameValuePair2("Use Encryption for Data", "0"))

 

 

        'Set the attributes for the boMainPropertyBag

        boMainPropertyBag.Collection.Add(New NameValuePair2("Database DLL", "crdb_ado.dll"))

        boMainPropertyBag.Collection.Add(New NameValuePair2("QE_DatabaseName", "ASP"))

        boMainPropertyBag.Collection.Add(New NameValuePair2("QE_DatabaseType", "OLE DB (ADO)"))

 

 

        'Add the QE_LogonProperties we set in the boInnerPropertyBag Object

        boMainPropertyBag.Collection.Add(New NameValuePair2("QE_LogonProperties", boInnerPropertyBag))

        boMainPropertyBag.Collection.Add(New NameValuePair2("QE_ServerDescription", crConnectionInfo.ServerName))

        boMainPropertyBag.Collection.Add(New NameValuePair2("QE_SQLDB", "True"))

        boMainPropertyBag.Collection.Add(New NameValuePair2("SSO Enabled", "False"))

        crConnectionInfo.Attributes = boMainPropertyBag

 

 

        Dim cryRpt As New ReportDocument

        cryRpt.Load(reportName)

        setReportDb(cryRpt, False)

        Return cryRpt

    End Function

 

 

    Private Sub setReportDb(ByRef report As ReportDocument, ByVal subR As Boolean)

 

 

        'Loop through each sub report in the report and apply the LogonInfo information

        'There seems to be an issue with subreports causing the app to crash. Solution for now is to set your log on info for the subreports first and then set the main report log on info.

        Dim sSubReportName As String

        Dim objTmpReport As ReportDocument

 

 

        For Each ReportObject In report.ReportDefinition.ReportObjects

            If ReportObject.GetType().Equals(GetType(SubreportObject)) Then

                sSubReportName = ReportObject.SubreportName

                objTmpReport = report.OpenSubreport(sSubReportName)

                setReportDb(objTmpReport, True)

            End If

        Next

 

 

        report.SetDatabaseLogon(o.dbUser, o.dbPassword, crConnectionInfo.ServerName, "ASP")

        For Each dsc As InternalConnectionInfo In report.DataSourceConnections

            ' Must set the UseDSNProperties flag to True before setting the database connection otherwise the connection does not work    

            If (dsc.LogonProperties.ContainsKey("UseDSNProperties")) Then

                dsc.LogonProperties.Set("UseDSNProperties", True)

            End If

            dsc.LogonProperties.Set("Data Source", crConnectionInfo.ServerName)

            dsc.SetConnection(crConnectionInfo.ServerName, "ASP", o.dbUser, o.dbPassword)

            Dim prt As String = ""

            For i As Integer = 0 To dsc.LogonProperties.Count - 1

                Dim nvp As NameValuePair2 = dsc.LogonProperties.Item(i)

                prt = prt & "Name=" & nvp.Name & ", Value=" & nvp.Value & System.Environment.NewLine

            Next

            MsgBox(prt)

        Next

 

 

        'Loop through each table in the report and apply the LogonInfo information

        CrTables = report.Database.Tables

        For Each Me.CrTable In CrTables

            crtableLogoninfo = CrTable.LogOnInfo

            crtableLogoninfo.ConnectionInfo = crConnectionInfo

            CrTable.ApplyLogOnInfo(crtableLogoninfo)

            Try

                CrTable.Location = CrTable.Name

            Catch ex As Exception

                MsgBox(ex.ToString)

                Exit Sub

            End Try

        Next

 

 

        If Not subR Then

            report.Refresh()

        End If

    End Sub

 

 

End Class

 

This is the prompts I am getting:

 

Image may be NSFW.
Clik here to view.

 

Image may be NSFW.
Clik here to view.

 

I noticed is that for some reason the datasource is picking up a database instance that is incorrect in the deployed environment.  Not sure where that comes from....  I have a database instance in my development environment but it is different.

 

Any help will be appreciated...


Viewing all articles
Browse latest Browse all 3636

Trending Articles