SQL SERVER REPORTING SERVICE WITH ASP.NET MVC
SQL Sever Reporting Service (SSRS) has a nice set of features and one of them is URL Accesswhich allows you to render reports directly to the response stream.
URL access of the report server in SQL Server Reporting Services (SSRS) enables you to send commands to a report server through a URL request.
A simple url which will return a report with no parameters would look like the following:
http://DOMAIN/ReportServer/Pages/ReportViewer.aspx?%2fXReports%2fNAME&rs:format=FORMAT&PARAMETERS
Let's examine each bold url property in the previous url example.
DOMAIN
IP address or domain of your report server.
NAME
The name of your report without the extension.
Obviously Sharepoint has specific needs so you need to include the *.rdl extension.
Obviously Sharepoint has specific needs so you need to include the *.rdl extension.
For SharePoint integrated mode, it is the fully qualified URL of the item in the SharePoint library, including the item extension.
FORMAT
The format in which to render a report.
There are several formats you can use, including: HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, and NULL, but don't expect great results if your report isn't neatly made for the specified format you would like to generate. Read more about the exports formats here.
There are several formats you can use, including: HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, and NULL, but don't expect great results if your report isn't neatly made for the specified format you would like to generate. Read more about the exports formats here.
Using PDF will mostly give you best results because it's a Hard page-break renderer extensionwhich means it will maintain the report layout and formatting.
PARAMETERS
To pass parameters you simply include the parameter name, an equal sign, and the value of the parameter. You don't need to prefix parameters like the URL Access Parameter which are used to configure the look and feel of your reports.
http://DOMAIN/ReportServer/Pages/ReportViewer.aspx?%2fXReports%2fNAME&rs:format=FORMAT&dateFrom={0}&dateTo={1}&id={2}
NOTE
To pass a null value for a parameter, useparameter:isnull=true
.
Beware the Prompt User property because if it's not selected in Report Manager you won't be able to pass a value for that report parameter within a URL.
By now you probably imagine how simple would be to write a simple MVC action which will generate report and show it to the user as *.pdf.
123456789101112131415161718192021222324252627282930 |
|
The code above is just a simple example but you can just as easily add more functionality: automatic task that generates your reports, saves them to disk with custom filenames, logs everything in your database etc.
1234567891011121314151617 |
|
0 comments:
Post a Comment
KOMENTAR