如何将我的水晶报告连接到网络中

时间:2014-03-05 09:35:57

标签: vb.net crystal-reports-2008

这是我的代码,当我打开我的水晶报告时,它总是给我一个需要填写用户名和密码的表格。我想禁用它。另一个问题是当我在我的计算机上安装我的项目时,我的项目正确运行但仍然需要填写用户和密码,如果我安装到网络或其他计算机,当我在本地主机中填写用户和密码时,它给我错误。

Private Sub AssignConnection(ByVal rpt As ReportDocument)         Dim connection As New ConnectionInfo()

    connection.DatabaseName = "pcba_info" 
    connection.ServerName = "192.168.0.201" 
    connection.UserID = "partschecker" 
    connection.Password = "sgic" 

    For Each table As CrystalDecisions.CrystalReports.Engine.Table In rpt.Database.Tables
        AssignTableConnection(table, connection)
    Next

    ' Now loop through all the sections and its objects to do the same for the subreports
    '
    For Each section As CrystalDecisions.CrystalReports.Engine.Section In rpt.ReportDefinition.Sections
        ' In each section we need to loop through all the reporting objects
        For Each reportObject As CrystalDecisions.CrystalReports.Engine.ReportObject In section.ReportObjects
            If reportObject.Kind = ReportObjectKind.SubreportObject Then
                Dim subReport As SubreportObject = DirectCast(reportObject, SubreportObject)
                Dim subDocument As ReportDocument = subReport.OpenSubreport(subReport.SubreportName)

                For Each table As CrystalDecisions.CrystalReports.Engine.Table In subDocument.Database.Tables
                    AssignTableConnection(table, connection)
                Next

                subDocument.SetDatabaseLogon(connection.UserID, connection.Password, connection.ServerName, connection.DatabaseName)
            End If
        Next
    Next
    rpt.SetDatabaseLogon(connection.UserID, connection.Password, connection.ServerName, connection.DatabaseName)
End Sub


Private Sub AssignTableConnection(ByVal table As CrystalDecisions.CrystalReports.Engine.Table, ByVal connection As ConnectionInfo)
    ' Cache the logon info block
    Dim logOnInfo As TableLogOnInfo = table.LogOnInfo

    connection.Type = logOnInfo.ConnectionInfo.Type

    ' Set the connection
    logOnInfo.ConnectionInfo = connection

    ' Apply the connection to the table!

    table.LogOnInfo.ConnectionInfo.DatabaseName = connection.DatabaseName
    table.LogOnInfo.ConnectionInfo.ServerName = connection.ServerName
    table.LogOnInfo.ConnectionInfo.UserID = connection.UserID
    table.LogOnInfo.ConnectionInfo.Password = connection.Password
    table.LogOnInfo.ConnectionInfo.Type = connection.Type
    table.ApplyLogOnInfo(logOnInfo)
End Sub

1 个答案:

答案 0 :(得分:0)

尝试一下

Public Sub LogOnToDatabase(ByRef pCrystalReport As CrystalDecisions.CrystalReports.Engine.ReportDocument)

p:pickList