2

Visual Studio 2010 では、次の設定を持つ XML ファイルに基づいて、Crystal Reports のリストを動的に作成しています。

<Report file="C:\reportname.rpt"    text="Report Name"
       imageURL="~/images/reporticon.png" />

私の ASPX ページには、次のような CrystalReportsViewer があります。

<CR:CrystalReportViewer ID="CrystalReportViewer" runat="server" AutoDataBind="true"
    Width="800px" Height="600px" CssClass="reportViewer"   HasCrystalLogo="False" />

ユーザーがレポート リンク (TreeNode オブジェクトから取得) をクリックすると、Crystal Report Viewer レポートは次のように設定されます。

 CrystalReportViewer.ReportSource = "C:\reportname.rpt";

実際の RPT レポート ファイルには接続文字列が保存されているため、Crystal Report Viewer はユーザーにユーザー名とパスワードの入力を求めません。

私の質問は、レポート ファイルに保存されている接続文字列を変更できるかどうかを確認することです。RPT ファイルを Crystal Reports Viewer にロードするときに接続文字列情報を設定するにはどうすればよいですか?

助けてくれてありがとう...

4

2 に答える 2

0

Web ビューアーが winforms ビューアーと同じかどうかはわかりませんが、新しい ReportDocument を作成し、レポート ファイルを ReportDocument にロードしてから、すべての接続情報を変更する必要がありました。

ReportDocument currentReport = new ReportDocument();  
currentReport.Load([path to .rept], OpenReportMethod.OpenReportByTempCopy);
ConnectionInfo crConnectionInfo = new ConnectionInfo();

//Set your connection params here  

for (int i = 0; i < currentReport.Database.Tables.Count; i++)
{
    Table crTable = currentReport.Database.Tables[i];
    TableLogOnInfo crTableLogOnInfo = crTable.LogOnInfo;
    crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
    crTable.ApplyLogOnInfo(crTableLogOnInfo);
}

foreach(IConnectionInfo cn in currentReport.DataSourceConnections)
{
    cn.SetConnection(_server, _database, _windowsAuth);        
    cn.SetLogon(_userName, _password);
}  

次に、レポート ビューアー ソースをレポート オブジェクトに設定します。

CrystalReportViewer.ReportSource = currentReport;
于 2012-06-25T21:53:26.127 に答える
0
Private Sub RecurseAndRemap(ByVal CR As Engine.ReportDocument)
        For Each DSC As CrystalDecisions.Shared.IConnectionInfo In CR.DataSourceConnections
            DSC.SetLogon("YourUserName", "YourPassword")
            DSC.SetConnection("YouServerName", "YourDatabaseName", False)
        Next

        CR.SetDatabaseLogon("YourUserName", "YourPassword")

        For Each Table As Engine.Table In CR.Database.Tables
            Table.LogOnInfo.ConnectionInfo.UserID = "YourUserName"
            Table.LogOnInfo.ConnectionInfo.Password = "YourPassword"
        Next

        If Not CR.IsSubreport Then
            For Each SR As Engine.ReportDocument In CR.Subreports
                RecurseAndRemap(SR)
            Next
        End If
    End Sub
于 2012-06-26T05:19:25.580 に答える