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
    Posts
    2

    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.
    Code:
    <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)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            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.SuspendLayout()
            '
            'CrystalReportViewer1
            '
            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")
            '
            'RptViewer
            '
            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.Controls.Add(Me.CrystalReportViewer1)
            Me.Name = "RptViewer"
            Me.Text = "RptViewer"
            Me.ResumeLayout(False)
            Me.PerformLayout()
    
        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
    Posts
    1,083

    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

    Code:
    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:
    Code:
    Dim crReportDocument As New CrystalReport1()
    'If you are using a Non-Typed report, and loading a report outside of the project, use the following:
    Code:
    Dim crReportDocument As New ReportDocument()
    
    crReportDocument.Load("c:\myReports\myReport.rpt")
    '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
    Code:
    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
    Code:
    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
        CrTable.ApplyLogOnInfo(crtableLogoninfo)
    
        '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)
    Next
    
    
    'Set the viewer to the report object to be previewed.
    CrystalReportViewer1.ReportSource = crReportDocument
    JG


    ... 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
    Posts
    2

    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
    Posts
    1,083

    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

    Code:
    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
        myTableLogonInfos.Add(myTableLogonInfo) 
        
        CrystalReportViewer1.LogOnInfo = myTableLogonInfos 
        CrystalReportViewer1.ReportSource = myReport 
    
    End Sub
    JG


    ... 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
  •  





Click Here to Expand Forum to Full Width

Featured