2016-12-01 6 views
-1

正常に実行できるCrystal Reportを作成しましたが、ログオン情報を入力する必要があります。私はgoogledとこのコードを見つけるが、それは私のために動作しませんでした。コードによる提案は高く評価されます。C#でCrystal Reportを読み込むときにログオン情報を保存する

private void frmPrintWIPReport_Load(object sender, EventArgs e) 
{ 
    var cryRpt = new ReportDocument(); 
    var crtableLogoninfo = new TableLogOnInfo(); 
    var crConnectionInfo = new ConnectionInfo(); 
    Tables CrTables; 

    cryRpt.Load("rptWIP.rpt"); 

    crConnectionInfo.ServerName = "192.168.40.253"; 
    crConnectionInfo.DatabaseName = "TNET"; 
    crConnectionInfo.IntegratedSecurity = true; 
    crConnectionInfo.UserID = "sa"; 
    crConnectionInfo.Password = "******"; 

    CrTables = cryRpt.Database.Tables; 
    foreach (Table CrTable in CrTables) 
    { 
     crtableLogoninfo = CrTable.LogOnInfo; 
     crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
     CrTable.ApplyLogOnInfo(crtableLogoninfo); 
    } 

    crystalReportViewer1.ReportSource = cryRpt; 
    crystalReportViewer1.Refresh(); 
} 
+0

「動作しません」とは何ですか?例外はありますか?エラーメッセージ?空の行ですか? – Martheen

+0

このレポートを開くときにログオンが必要です!私はログオンのダイアログが表示される必要はありません! – user3035133

答えて

0

これを試すことができます。私はそれがあなたの必要と同じであることを願っています。

private void frmPrintWIPReport_Load(object sender, EventArgs e) 
    { 
     var cryRpt = new ReportDocument(); 
     var crtableLogoninfo = new TableLogOnInfo(); 
     var crConnectionInfo = new ConnectionInfo(); 
     Tables CrTables; 

     cryRpt.Load("rptWIP.rpt"); 

     ConnectionInfo crConnectionInfo = new ConnectionInfo() 
      { 
       ServerName = @"192.168.40.253", 
       DatabaseName = @"TNET", 
       [email protected]"sa", 
       [email protected]"******"     
       //IntegratedSecurity = true 
      }; 

     CrTables = cryRpt.Database.Tables; 
     foreach (Table CrTable in CrTables) 
     { 
      crtableLogoninfo = CrTable.LogOnInfo; 
      crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
      CrTable.ApplyLogOnInfo(crtableLogoninfo); 
     } 

     crystalReportViewer1.ReportSource = cryRpt; 
     crystalReportViewer1.Refresh(); 
    } 
関連する問題