2013-10-28 54 views
0
打開水晶報表

我試圖打開我的網站水晶報表,但它給了一個錯誤 這裏是我試圖錯誤在ASP.NET

protected void report_view(object sender, EventArgs e) 
    { 
    ReportDocument cryRpt = new ReportDocument(); 
    TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 
    ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
    Tables CrTables; 

    cryRpt.Load("C:\\Report1.rpt"); 

    crConnectionInfo.ServerName = "local"; 
    crConnectionInfo.DatabaseName = "MyEmployees"; 
    crConnectionInfo.UserID = "MYLAPTOP\\HOME"; 

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

    CrystalReportViewer1.ReportSource = cryRpt; 
    CrystalReportViewer1.RefreshReport(); 
    } 

這裏的代碼在CrystalReportViwer所示的錯誤

Failed to open the connection. Failed to open the connection. Report1 {1222DD0B-C24E- 4E66-8EE1-7ED7F5F0D6B4}.rpt 

我使用Visual Studio 2010中使用Crystal Reports 11

回答

1

看來你在聲明連接細節時丟失密碼。嘗試添加它:

crConnectionInfo.ServerName = "local"; 
crConnectionInfo.DatabaseName = "MyEmployees"; 
crConnectionInfo.UserID = "MYLAPTOP\\HOME"; 
crConnectionInfo.Password = "Password"; //Swap with real password of course 

確保所有文件路徑和文件名都是正確的。

或者,您可以查看SetDataBaseLogon() method

+0

數據庫不受密碼保護。 。 。 –

+0

親自我懷疑服務器名稱,數據庫是本地的,所以這就是爲什麼我把服務器名稱作爲本地,相同在SqlServer UserID也是在SqlServer用戶名相同 –

+0

SetDataBaseLogon()方法爲我工作,謝謝@Conrad Lotz –