0

サブレポートを持つVisual StudioのCrystalレポートがあります。メインレポートの資格情報を渡すことはできますが、サブレポートの資格情報は渡すことはできません。サブレポートのパスワードを入力するよう求められます。メインレポートとサブレポートの資格情報を渡すにはどうすればよいですか?彼らは異なるデータベースから同じサーバから引き出しています。私は、メインレポートにログインするには、次のコードを使用していますCrystalサブレポートのログイン情報

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 

私は私が設定したパラメータが表示していますし、中にこれらの選択を通過した後、サブレポートのログイン情報がありますパスワードを入力する必要があります。私はこれをユーザー入力なしで自動的に渡したいと思います。

答えて

0

この問題を遭遇する他の人にとっては、私は同僚と私が見つけて見つけたものを投稿します。

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 
メインレポート資格情報をコード化する前に、サブレポート情報をコーディングする必要があることに注意することが重要です
関連する問題