Link to home
Start Free TrialLog in
Avatar of wykzimme
wykzimme

asked on

Crystal Reports Runtime/database login information

I have a windows form with a CrystalReportViewer, button, and OpenFileDialog.

I would like the user to be able to select the report to view but I want the application to supply the username/password.  I really don't want the Database Login dialog box to appear.  Is this possible?

I tried:
 Private Sub btnOpenReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenReport.Click
        OpenFileDialog1.Filter = "Crystal Reports|*.RPT"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            CrystalReportViewer1.ReportSource = OpenFileDialog1.FileName
        End If

    End Sub

    Private Sub CrystalReportViewer1_ReportRefresh(ByVal source As Object, ByVal e As CrystalDecisions.Windows.Forms.ViewerEventArgs) Handles CrystalReportViewer1.ReportRefresh
        Dim logOnInfo As New TableLogOnInfo
        logOnInfo.ConnectionInfo.ServerName = "servername"
        logOnInfo.ConnectionInfo.DatabaseName = ""
        logOnInfo.ConnectionInfo.UserID = "username"
        logOnInfo.ConnectionInfo.Password = "password"
        CrystalReportViewer1.LogOnInfo.Add(logOnInfo)
    End Sub
Avatar of redundguy
redundguy

Try

Instead of
CrystalReportViewer1.LogOnInfo.Add(logOnInfo)

you can use:
vnt=reportdocumentobject.Database.tables.count
for i=0 to vnt-1
    reportdocumentobject.Database.tables(i).ApplyLogonInfo(logoninfo)
next

and maybe you need:
logoninfo=reportdocumentobject.Database.tables(0).logoninfo
before:
logOnInfo.ConnectionInfo.ServerName = "servername"

George
Avatar of wykzimme

ASKER

ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial