SSRS(七):ASP.Net 網頁引用報表資料

做好的報表要如何套用在自己的網站呢?這篇教學要教各位將SQL Server Reporting Server上的報表套用在自己的網站上,然後還可以自行參數至報表裡。以下以 Visual Studio 2010 做示範,原則上做法和RDLC類似,只是不需要丟資料進去而以。

1. 新增一個專案或網站,加入Web Form,加入ScriptManagerReportViewer,將ReportViewer選擇伺服器報表,報表伺服器URL和報表路徑依照報表所設定

Add ScriptManager And ReportViewer

2. 執行報表結果

View Reporting Result

3. 如果要傳參數至報表裡,可以使用程式來傳入。

[vb]Imports Microsoft.Reporting.WebForms

Protected Sub Page_Load(…)
If Not IsPostBack Then
ReportViewer1.ServerReport.SetParameters(New ReportParameter("Country", "USA"))
ReportViewer1.ShowParameterPrompts = False ‘報表不顯示參數設定
ReportViewer1.ServerReport.Refresh()
End If
End Sub[/vb]

4. 執行結果

View Reporting Result

5. 如果執行報表出現錯誤,通常是報表或者資料庫安全性問題,因為是Server端的報表,安全性會比較嚴謹。可先至報表管理員設定安全性,加入相關使用者權限,在這裡我們加入 NT AUTHORITYNETWORK SERVICE 的角色為 瀏覽器

Set Reporting Permission

6. 在資料庫部分也設定 NT AUTHORITYNETWORK SERVICE存取 NorthWind 的讀寫權限,可依照需求自行調整

Set SQL Server Permission

後記:SQL Server Reporting Server 大致上完成初步簡單的系列教學,之後如果還有機會將會在持續分享給各位。

SSRS(SQL ServerReporting Services)系列文章:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>