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

Posted on 2009-12-29
Last Modified: 2012-05-08
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

Question by:SheldonC

    Author Comment

    Here is the image file with the login request.
    LVL 100

    Assisted Solution

    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

    LVL 69

    Assisted Solution

    by:Éric Moreau
    that's in part why I prefer to pass a filled dataset to my reports. see

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now