How to set database login infos (connection info) for crystal report vb.net?

断了今生、忘了曾经 提交于 2019-12-12 02:14:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!