我有一個SQL數據庫和一個ASP.NET網站,用於將數據放入數據庫。在ASP.NET中報告
其中一個項目的要求是建立一個系統,讓用戶上傳Crystal報表服務器,並根據需要運行它。通過這種方式,用戶可以創建一個定製的報告(然後轉變爲管理層,客戶),而不會強迫他們通過開發人員。
我在尋找如何完成此目標的建議。
目前,我正在尋找一種方法來重定向從它與該數據庫最終將運行在開發數據庫中的水晶報表數據庫連接。然而,似乎沒有一種簡單的方法來做到這一點。
我還在研究ReportViewer對象。但是,我所看到的所有代碼都涉及在代碼中指定報告的查詢,這是不可接受的。
一個選項(這是我不喜歡的話),就是讓他們寫自己的查詢,這樣他們就可以將結果複製到Excel中。這將意味着一個空白的文本框和關於數據庫結構的信息。由於多種原因,這不是一個好主意。
另一種選擇是爲每個表(或者再加上一些額外的)一個報告,讓用戶複製他們希望到Excel中的數據,並繼續自己快樂的方式。
tl; dr如何建立靈活的報告系統?
=========================================
繼續: 2012年8月20日
我決定去b.pell的擴展方法的路線。到目前爲止,它比其他任何東西都更接近我。我的代碼綁定到CrystalReportViewer如下:
CrystalReportSource rs = new CrystalReportSource();
rs.Report.FileName = Server.MapPath("ReportFiles/") + Request["reportname"];
string connstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
rs.ReportDocument.ApplyCredentialsFromConnectionString(connstring);
rs.ReportDocument.ApplyNewDatabaseName("myDBName", "mySchemaName");
rs.ReportDocument.Refresh();
CrystalReportViewer1.ReportSource = rs;
這非常接近工作。它工作正常,我的開發機器上,但是當我在服務器上運行的代碼,它提供了以下錯誤:
Logon failed.Error in File CrystalReport2 {5D2E82E5-783E-4DFD-A770-C8AE72A51E4E}.rpt: Unable to connect: incorrect log on parameters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Logon failed.Error in File CrystalReport2 {5D2E82E5-783E-4DFD-A770-C8AE72A51E4E}.rpt: Unable to connect: incorrect log on parameters. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
的錯誤是在這行代碼:
crTable.Location = String.Format("{0}{1}", prefix, crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1))
當我刪除對ApplyNewDatabaseName的調用,我被要求輸入服務器名稱,數據庫名稱,用戶名和密碼或選擇集成安全性。我無法輸入數據庫名稱或服務器名稱(這些字段被禁用)。
有什麼想法?
Reporting Services聽起來像它可能工作。你有一個建議的教程,讓我開始? – Brynne 2012-08-16 21:11:51
@notkilroy還沒看過,但我認爲這是一個教程[Reporting Services](https://www.microsoftvirtualacademy.com/tracks/breakthrough-insights-using-microsoft-sql-server-2012-reporting-services) – saul672 2012-08-16 21:29:47