joe joe - 2 months ago 25
Vb.net Question

vb.net .VerifyDatabase for Crystal Reports using a password restricted Access DB

As the question title suggests, my vb.net project that uses Crystal Reports 9 and a password restricted MS-Access 97 database.

When loading reports, the

Load
method calls
cReport.VerifyDatabase()
which has previously been working fine without a password, but since adding one, it isn't working, and gives me the following error


Log on failed.
at CrystalDecisions.CrystalReports.Engine.ReportDocument.VerifyDatabase()


What do I need to add/change to this code for it to log on successfully?

Private Sub frmReportViewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Try
setFormSizes(Me, con)
Me.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2), 10)
Me.Text = "Report Viewer - (" & Replace(cReport.FileName, "rassdk://", "") & ")"

cReport.VerifyDatabase()
cReport.Refresh()

crViewer.ReportSource = cReport
crViewer.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
crViewer.Zoom(87)

Catch ex As Exception
errorLog(ex)

End Try
End Sub


EDIT

The data can be viewed when opening the report file in Crystal Reports itself, but this is because I can manually enter the password.

Answer

As per MSDN

 Dim logOnInfo As New TableLogOnInfo()
        Dim i As Integer

        For i = 0 To cReport.Database.Tables.Count - 1
            logOnInfo.ConnectionInfo.DatabaseName = "Database_Name"
            logOnInfo.ConnectionInfo.Password = "Password"
            cReport.Database.Tables.Item(i).ApplyLogOnInfo(logOnInfo)
        Next i
Comments