0

Ich habe einen Crystal-Bericht in Visual Studio, der einen Unterbericht hat. Ich kann Anmeldeinformationen für den Hauptbericht, aber nicht für den Unterbericht übergeben. Ich werde aufgefordert, das Passwort für den Unterbericht einzugeben. Wie kann ich Anmeldeinformationen für den Hauptbericht und den Unterbericht weitergeben? Sie ziehen aus verschiedenen Datenbanken, aber vom selben Server.Crystal Login-Informationen für Subreport

ich den folgenden Code verwenden in den Hauptbericht zu protokollieren:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Try 
     Dim cryRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument 
     Dim crtableLogoninfos As New TableLogOnInfos 
     Dim crtableLogoninfo As New TableLogOnInfo 
     Dim crConnectionInfo As New ConnectionInfo 
     Dim CrTables As CrystalDecisions.CrystalReports.Engine.Tables 
     Dim CrTable As CrystalDecisions.CrystalReports.Engine.Table 

     cryRpt.Load("\\Server\reportPath\report.rpt") 
     CrystalReportViewer1.ReportSource = cryRpt 
     With crConnectionInfo 
      .ServerName = "Server" 
      .DatabaseName = "MainDatabase" 
      .UserID = "User" 
      .Password = "Password!" 
     End With 
     CrTables = cryRpt.Database.Tables 
     For Each CrTable In CrTables 
      crtableLogoninfo = CrTable.LogOnInfo 
      crtableLogoninfo.ConnectionInfo = crConnectionInfo 
      CrTable.ApplyLogOnInfo(crtableLogoninfo) 
      CrTable.TestConnectivity() 
     Next 
    Catch ex As Exception 
     MsgBox("You cannot Connect to the Database") 

    End Try 
End Sub 

ich mit den Parametern Angeregt bin, die ich festgelegt habe, und nachdem diese Auswahl in den Login-Informationen für den Teilbericht vorbei sind aufgefordert und das Passwort ist erforderlich. Ich möchte das automatisch ohne Benutzereingaben weitergeben.

Antwort

0

Für jeden anderen, der auf dieses Problem stößt, poste ich, was ein Kollege und ich fand und dachte. Es ist wichtig zu beachten, dass Sie die Informationen für den Unterbericht codieren sollten, BEVOR Sie die Hauptanmeldeinformationen des Berichts codieren:

Imports System.Data.SqlClient 
Imports CrystalDecisions.CrystalReports.Engine 
Imports CrystalDecisions.Shared 

Public Class VndPerfReport 
Private Sub ApplyNewServer(ByVal report As ReportDocument) 

    For Each subReport As ReportDocument In report.Subreports 
     For Each crTable As Table In subReport.Database.Tables 
      Dim loi As TableLogOnInfo = crTable.LogOnInfo 
      loi.ConnectionInfo.ServerName = "Servername" 

      loi.ConnectionInfo.UserID = "User" 
      loi.ConnectionInfo.Password = "Password" 

      crTable.ApplyLogOnInfo(loi) 
     Next 
    Next 
    'Loop through each table in the report and apply the new login 
    For Each crTable As Table In report.Database.Tables 
     Dim loi As TableLogOnInfo = crTable.LogOnInfo 
     loi.ConnectionInfo.ServerName = "Servername" 

     loi.ConnectionInfo.UserID = "User" 
     loi.ConnectionInfo.Password = "Password" 

     crTable.ApplyLogOnInfo(loi) 
     'If your DatabaseName is changing at runtime, specify the table location. 
     'crTable.Location = ci.DatabaseName & ".dbo." & crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1) 
    Next 
End Sub 

Private Sub VndPerfReport_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    ApplyNewServer(CrystalReportViewer1.ReportSource) 
End Sub 
End Class 
Verwandte Themen