问题
I am having a little problem getting Crystal Reports to set the logon. I have it working in a number of reports but a couple for some reason have stopped working. Attached is my logon script, I have stepped through it and the logon info is all there after every step.
What is even more unusual is that the report in visual studio will open with information OK
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
Dim cryRpt As New ReportDocument
Dim crTableLogonInfos As New TableLogOnInfos
Dim crTableLogonInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As Tables
Dim crTable As Table
cryRpt.Load("g:\dt2\rptMusterSheet.rpt")
With crConnectionInfo
.ServerName = "SERVERNAME"
.DatabaseName = "DB NAME"
.UserID = "sa"
.Password = "xxxxxxx"
End With
crTables = cryRpt.Database.Tables
For Each crTable In crTables
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogonInfo)
Next
CRV1.ReportSource = cryRpt
CRV1.Refresh()
End Sub
after stepping through I get thisMessage Box
回答1:
Try this ...
Dim mytableloginfos As New TableLogOnInfos()
mytableloginfos = CRV1.LogOnInfo
For Each myTableLogOnInfo As TableLogOnInfo In mytableloginfos
myTableLogOnInfo.ConnectionInfo = crConnectionInfo
Next
来源:https://stackoverflow.com/questions/35419759/how-to-set-database-login-infos-connection-info-for-crystal-report-vb-net