• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Running a Crystal Report in a VB .Net 2008 Application on Client after installation

When I try to generate the report I get the attached prompt asking me to log in but the database path and server name are pointing to where the database was located on the computer that the application was developed.

Below I have included the code where I passed the parameters.

        Dim cryRpt As New ReportDocument
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crpfdRegNo As ParameterFieldDefinition
        Dim crpfdDate As ParameterFieldDefinition
        Dim crpvDate As New ParameterValues, crpvRegNo As New ParameterValues
        Dim crpdvDate As New ParameterDiscreteValue
        Dim crpdvRegno As New ParameterDiscreteValue

        If dgvList.Rows.Count = 0 Then Exit Sub

        Me.Cursor = Cursors.WaitCursor

        cryRpt.Load(System.AppDomain.CurrentDomain.BaseDirectory & "C3Statement.rpt")

        'Get the parameter fields from the crystal report
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields

        'Get specified parameter from the definition
        crpfdDate = crParameterFieldDefinitions.Item("C3Date")
        crpfdRegNo = crParameterFieldDefinitions.Item("regnum")

        ''Get the current values from the parameter field.  At this point
        ''there are zero values set.
        crpvDate = crpfdDate.CurrentValues
        crpvRegNo = crpfdRegNo.CurrentValues

        'Fill Date Parameter
        crpdvDate.Value = dgvList.CurrentRow.Cells(1).Value
        'Fill Registration Number parameter
        crpdvRegno.Value = dgvList.CurrentRow.Cells(0).Value

        frmPrint.crvViewReport.ReportSource = cryRpt

  • 2
3 Solutions
SheldonCAuthor Commented:
Here is the image file with the login request.
If you login does the report run or does the client have a different database?

You can change the database through the application
Look starting on page 113 in this walkthrough


Éric MoreauSenior .Net ConsultantCommented:
that's in part why I prefer to pass a filled dataset to my reports. see http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
SheldonCAuthor Commented:
I needed to pass the connection information to the Report. I found the following functions somewhere but I can't remember where.

 Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean

        Dim li As TableLogOnInfo
        Dim tbl As Table

        ' for each table apply connection info  
        For Each tbl In cr.Database.Tables
            li = tbl.LogOnInfo
            li.ConnectionInfo = ci

            ' check if  logon was successful  
            ' if  TestConnectivity returns false,  
            ' check logon credentials  
            If (tbl.TestConnectivity()) Then
                'drop fully qualified table location  
                If (tbl.Location.IndexOf(".") > 0) Then
                    tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
                    tbl.Location = tbl.Location
                End If
                Return False
            End If
            Return True
    End Function

    Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String, ByVal id As String, ByVal pass As String) As Boolean

        Dim ci As New ConnectionInfo
        Dim subObj As SubreportObject
        Dim obj As ReportObject

        ci.ServerName = server
        ci.DatabaseName = db
        ci.UserID = id
        ci.Password = pass

        If Not (ApplyLogon(cr, ci)) Then
            Return False
        End If

        For Each obj In cr.ReportDefinition.ReportObjects
            If (obj.Kind = ReportObjectKind.SubreportObject) Then
                subObj = CType(obj, SubreportObject)
                If Not (ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) Then
                    Return False
                End If
            End If
        Return True
    End Function


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now