2015-12-15 38 views
0

我每次加載水晶報表時都遇到了問題。總是要求數據庫登錄,但是當我輸入密碼(這是我的連接密碼)時,它總是說登錄失敗。加載水晶報表時提示數據庫登錄

這是我的代碼:

Dim _ReportLogonInfos As New TableLogOnInfos 
    Dim _ReportLogonInfo As New TableLogOnInfo 
    Dim _ReportConInfo As New ConnectionInfo 
    Dim _Tables As Tables 
    Dim _Table As Table 

    With _ReportConInfo 
     .ServerName = "localhost" 
     .DatabaseName = "database" 
     .UserID = "root" 
     .Password = "Qwerty123" 
    End With 
    Dim _Report As New rptPrntIss 
    _Tables = _Report.Database.Tables 
    For Each _Table In _Tables 
     _ReportLogonInfo = _Table.LogOnInfo 
     _ReportLogonInfo.ConnectionInfo = _ReportConInfo 
     _Table.ApplyLogOnInfo(_ReportLogonInfo) 

    Next 
    CrystalReportViewer1.ReportSource = _Report 

回答

0

除了您所設置的,我還設置了以下(抱歉,這是在C#中沒有VB.NET - 希望你能翻譯):

 //SET DATASOURCE FOR EACH SUBREPORT IN REPORT 
     foreach (CrystalDecisions.CrystalReports.Engine.Section section in CrystalReportSource2.ReportDocument.ReportDefinition.Sections) 
     { 
      // In each section we need to loop through all the reporting objects 
      foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects) 
      { 
       if (reportObject.Kind == ReportObjectKind.SubreportObject) 
       { 
        SubreportObject subReport = (SubreportObject)reportObject; 
        ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName); 

        foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables) 
        { 
         // Cache the logon info block 
         TableLogOnInfo logOnInfo = table.LogOnInfo; 

         // Set the connection 
         logOnInfo.ConnectionInfo = crConnectionInfo; 

         // Apply the connection to the table! 
         table.ApplyLogOnInfo(logOnInfo); 
        } 
       } 
      } 
     } 
 if (CrystalReportSource2.ReportDocument.DataSourceConnections.Count > 0) 
      CrystalReportSource2.ReportDocument.DataSourceConnections[0].SetConnection(server, db, crystalUser, pwd); 
 CrystalReportSource2.ReportDocument.SetDatabaseLogon(crystalUser, pwd, server, db); 
+0

謝謝你..我已經解決了它。感謝這個幫助..你給我的想法..所以我可以繼續我的項目。上帝保佑 :) – SyZ

相關問題