troubleshooting Question

CR XI Report from SQL Stored Procedure

Avatar of dgoncher
dgoncher asked on
Crystal Reports
14 Comments1 Solution301 ViewsLast Modified:
I can't seem to get this report to get the logon info passed.  The report is based on a SQL Stored Procedure.  My users keep getting the Database login dialog box.  It has the Servername, Login ID and Password but the database is blank (and you cannot enter it).  I've been trying the suggestions on this website to no avail.  The User passed in has dbo rights to the db and rights to execute the stored proc.  I've tried it with a sub report and without a sub report.  VS2005  CR XI

Here is my function
 Friend Function ViewReport(ByVal sReportName As String) As Boolean

        'Declaring variables
        Dim intCounter As Integer
        Dim intCounter1 As Integer

        'Crystal Report's report document object
        Dim objReport As New _

        'object of table Log on info of Crystal report
        Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo

        'Sub report object of crystal report.
        Dim mySubReportObject As _

        'Sub report document of crystal report.
        Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument      
        Dim index As Integer


            'Load the report

            objReport.SetDatabaseLogon("XXUSER", "USERPWD")

            ConInfo.ConnectionInfo.UserID = "XXUSER"
            ConInfo.ConnectionInfo.Password = "USERPWD"
            ConInfo.ConnectionInfo.ServerName = "SqlServer1"
            ConInfo.ConnectionInfo.DatabaseName = "DB109"


            ' Loop through each section on the report then look
            ' through each object in the section
            ' if the object is a subreport, then apply logon info
            ' on each table of that sub report

            For index = 0 To objReport.ReportDefinition.Sections.Count - 1
                For intCounter = 0 To _
                      objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
                    With objReport.ReportDefinition.Sections(index)
                        If .ReportObjects(intCounter).Kind = _
                           CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
                            mySubReportObject = CType(.ReportObjects(intCounter), _
                            mySubRepDoc = _

                            For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
                              ' Tried setting twice
                              '  mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
                        End If
                    End With
            CrystalReportViewer1.ReportSource = Nothing

            objReport.SetDatabaseLogon("XXUSER", "USERPWD")

            'Set the current report object to report.

            CrystalReportViewer1.ReportSource = objReport

            Return True
        Catch ex As System.Exception
        End Try
    End Function

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros