CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012

    VB Crystal Viewer prompting login. Cannot figure it out. Have read posts on this...

    I have a VS 2008 app I am building. I REALLY need your help VB Crystal Reports Experts! Works great but asks for database credentials when Crystal Reports Viewer attempts to launch the report. The stucture is that the app passes parameters to a stored procedure on a MS SQL box which creates a temporary table. Then the CR inside of the CRviewer reports on the temporary table. All works fine except that the user is prompted for DB credentials (information they are not allowed to know), when the CRviewer launches. I have been struggling with this for a week! I have searched and searched the code here and everywhere else but I cannot find something that works or if I do find something, I am affraid to try it because I don't know where it should go? I think maybe it needs to be part of this but I don't know if this is where it belongs or what the code should be.
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class RptViewer
        Inherits System.Windows.Forms.Form
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                If disposing AndAlso components IsNot Nothing Then
                End If
            End Try
        End Sub
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.CrystalReportViewer1 = New CrystalDecisions.Windows.Forms.CrystalReportViewer
            Me.Exp_Auth1 = New AuthApp.Exp_Auth
            Me.CrystalReportViewer1.ActiveViewIndex = 0
            Me.CrystalReportViewer1.AutoSize = True
            Me.CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.CrystalReportViewer1.DisplayGroupTree = False
            Me.CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
            Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
            Me.CrystalReportViewer1.ReportSource = Me.Exp_Auth1
            Me.CrystalReportViewer1.Size = New System.Drawing.Size(1034, 1054)
            Me.CrystalReportViewer1.TabIndex = 0
            Me.SetDatabaseLogon("pwhcprod01", "Pwhcprod01")
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(1034, 1054)
            Me.Name = "RptViewer"
            Me.Text = "RptViewer"
        End Sub
        Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
        Friend WithEvents Exp_Auth1 As AuthApp.Exp_Auth
    End Class

    ALL help is very much appreciated. I am a newbie but I have built a great app that fully meets some complex business requirements. All I need now is to get past this one last thing!!!

  2. #2
    Join Date
    Jul 2005

    Re: VB Crystal Viewer prompting login. Cannot figure it out. Have read posts on this.

    Read this general information about VB.NET & Crystal Reports
    It could be helpful

    'To pass logon information to a Crystal Report at runtime

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    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
    'If you are using a Strongly Typed report (Imported in your project) named CrystalReport1.rpt use the following:
    Dim crReportDocument As New CrystalReport1()
    'If you are using a Non-Typed report, and loading a report outside of the project, use the following:
    Dim crReportDocument As New ReportDocument()
    'Set the ConnectionInfo properties for logging on to the Database

    'If you are using ODBC, this should be the DSN name NOT the physical server name.
    'If you are NOT using ODBC, this should be the physical server name
    With crConnectionInfo
        .ServerName = "DSN or Server Name"
    'If you are connecting to Oracle there is no DatabaseName. Use an empty string. For example, .DatabaseName = ""
        .DatabaseName = "DatabaseName"
        .UserID = "Your User ID"
        .Password = "Your Password"
    End With
    'This code works for both user tables and stored procedures.
    'Set the CrTables to the Tables collection of the report
    CrTables = crReportDocument.Database.Tables
    'Loop through each table in the report and apply the LogonInfo information
    For Each CrTable in CrTables
        CrTableLogonInfo = CrTable.LogonInfo
        CrTableLogonInfo.ConnectionInfo = crConnectionInfo
        'If your DatabaseName is changing at runtime, specify the table location.
        'For example, when you are reporting off of a Northwind database on SQL server you should have the following line of code:
        crTable.Location = "Northwind.dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
    'Set the viewer to the report object to be previewed.
    CrystalReportViewer1.ReportSource = crReportDocument

    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Join Date
    Nov 2012

    Re: VB Crystal Viewer prompting login. Cannot figure it out. Have read posts on this.

    Thank you for your reply. I have seen this before and attempted to use it. I failed. I don't know if I was even attempting correctly because to begin I do not know where this code should go. Does it go into the code for the CR viewer page? Does it go into the code for the main application that is launching the CR viewer? Does the fact that my CR is run off of a temporary table which is created by the main application and then reported upon by the CR change the situation? This works correctly. I have all the parameters passing to the SP and all the data is coming into the the temp table in the tempdb. But when the CR viewer is launched as another form from the main application; it asks for the database credentials at this time. Everything I have done to attempt to embed these credentials has either not changed the situation and all runs the same. Or it causes the report to come up blank even though the data is all in the table when I look at the table in MS SQL. I would love it if you could tell me where to put the code and if you see any basic flaws in what I am doing. Sorry for being such a newbie. I am learning quick! Thanks.

  4. #4
    Join Date
    Jul 2005

    Re: VB Crystal Viewer prompting login. Cannot figure it out. Have read posts on this.

    The code could go in any event you want, in this example it goes in the form load event;
    it could be in the click event of the command button where you call the report

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        Dim myReport = New YourReportNameHere() 
        Dim myTableLogonInfos = New CrystalDecisions.Shared.TableLogOnInfos() 
        Dim myTableLogonInfo = New CrystalDecisions.Shared.TableLogOnInfo() 
        Dim myConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo() 
        With myConnectionInfo 
            .ServerName = “YourServerName” 
            .DatabaseName = “YourDBname” 
            .UserID = “YourUserID” 
            .Password = “YourPassword”
        End With
        myTableLogonInfo.ConnectionInfo = myConnectionInfo 
        myTableLogonInfo.TableName = “customers”  '<-----YourTableName
        CrystalReportViewer1.LogOnInfo = myTableLogonInfos 
        CrystalReportViewer1.ReportSource = myReport 
    End Sub

    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.