Home >

Create PDF via SQL Server Reporting Service or Report Viewer Control

23. February 2011

(Note: source code is available at the end of this post)

Data driven PDF could mean: thousands PDF files created by a server scheduled job, which renders PDFs from a database query or a web site which generate a dynamic PDF file based on user inputs and clicks.

There are two technologies offered by Microsoft to realize this dynamic data driven PDF generation: SSRS (SQL server Reporting Service) and  Report Viewer Control.

I made two dynamic PDF creating web applications, one is using SSRS approach, the other is using Report Viewer Control approach.

SSRS approach (live demo) is coded via VS 2010 (Web application) + VS 2008 (RDLC creator)

image

Report Viewer Control approach (live demo) is coded via VS 2010

image

To make you understand the source code easier, I compiled a FAQ list to explain some basic terms and concepts about the SSRS and Report Viewer Control

============================================================

Claim: following FAQs are just my personal understanding about the SSRS and Report Viewer Control. I can’t guarantee its technical right, so please take it as is. But one thing I can guarantee is that these understandings serve my projects very well. In addition, these FAQs are far from a real introduction of the two software, because the topic is just too big to cover in this article. If you are really interested to know further, go MSDN to find out more.

============================================================

1Q: What are the installation and configuration difference between the two?

A: SSRS is a much bigger software application. SSRS is part of SQL server since SQL 2005, the installation files are hundreds MBs and takes around half hour or even hours to install and configure properly. Report Viewer Control is much smaller, it’s either already part of your .NET 3.5 or 4.0 environment, or you can install it separately. You can download Report Viewer Control 2010 Redistributable Package from Microsoft (here), only 4.5 MB. The installation will put necessary DLLs to GAC (usually c:\windows\assembly). You could install this RVC package on your local developer PC or production server in about 5 minutes.

2Q: Can SSRS be installed stand alone (without SQL database in one physical box)?

A: Yes. The SSRS installation doesn’t need to have SQL Database in one box, but SSRS still needs to “point” or “link” to an existing SQL server database instance. Because all the configurations and reports definitions are eventually saved in the database, the configuration database for SSRS by default named as “ReportServer” and “ReportServerTempDB”.

This is very good for multitier enterprise solution (data is at the safest place, Report engine and/or report definitions & web pages are at web server)

3Q: Does SSRS need IIS?

A: In SQL 2005, it does need IIS to be together in one box because it needs IIS to host its web service interface and web portal interface (although you can hide both UIs from the end users). In SQL 2008, SSRS has its own embedded web server, and doesn’t need IIS anymore.

4Q: Does SSRS need Active Directory or Domain?

A: Not necessary. SSRS can be setup as totally independent server, no AD/Domain at all, although AD/Domain setup can bring it to normal enterprise security level.

5Q: License or cost of the two?

A: Mean and lean speaking, both solutions are free. well if you already bought SQL server standard and/or above licenses, SSRS is included already. If you are just using free edition of SQL server, SQL server express edition, SSRS is licensed free. Report Viewer Control is always free to use and distribute. The PDF generation itself is also free. No need to pay ADOBE license fee to do it.

6Q: What is RDL (Report Definition Language) or RDLC and how does it apply to two software?

A: RDL is a file extension, such as “rpt01.rdl”. It’s a pure text XML file. RDLC is pretty much the same as RDL (slight different, explained more at 8Q), “C” means “client” or something similar. Basically, RDL is the skeleton, layout and structure of the report, data (from query against the SQL DB) is the meat. SSRS + RDL + Data will give you a rendered report either in HTML or other formats (PDF, WORD, Excel). RDLC usually is applied to Report Viewer Control, but still served the same purpose as RDL as a skeleton of the report. So Report Viewer Control + RDLC + Data will also render you a report. By the way, Report Viewer Control can also link to RDL on SSRS.

7Q: Where is RDL or RDLC physically sitting

A: RDL and RDLC are pure text XML files.

RDL can be deployed to SSRS server. “Deploy” is the process to put RDL into SSRS configuration databases which are “ReportServer” and “ReportServerTempDB” (see 2Q). Deployment can be done via Visual Studio or SSRS web management portal (see 9Q).

RDLC can be part of your ASP.NET web application or windows form application (either in file system or resource file)

8Q: What are the tools to create RDL or RDLC

A: RDL is created from Visual studio Business Intelligence Project Template (some time it is referred as Business Intelligence Studio or BI studio). As for PC development, you install Visual Studio first, then install SQL server (Any edition). The Business Intelligence template is in the SQL server installation package. This template is very sensitive to VS versions , which means, You can only use VS 2005 + SQL server 2005 BI studio to create RDL for SSRS 2005, and use VS 2008 + SQL server 2008 BI studio to create RDL for SSRS 2008. No VS 2010 template at the moment.

RDLC is much easier, because you can directly create it from normal visual studio project (either win form or web application) as long as you set the reference to the Report Viewer Control library.

9Q: What are the URLs for SSRS web management and SSRS web service?

A: SSRS web management portal is for admin works (such as setup data source, online folders, security, adjust reports parameters, schedules etc.).  Usually the local installation URL is like: http://localhost/Reports. You can open it and do most SSRS admin works.

SSRS web service is for rendering reports during the run time. SSRS web service URL is like: http://localhost/Reportserver/ReportExecution2005.asmx, even in SSRS 2008, you will still have to use ReportExecution2005.asmx as the report rendering web service.

When you deploy RDL from VS 2008 BI stuidio (i.e. Business Intelligence Project Template), you setup the deploy folder to http://localhost/Reportserver/<your report folder>.

10Q: How does SSRS or Report Viewer Control create PDF under the hood?

A: SSRS creates PDF or other format of the report through ReportExecution2005.asmx web service.

You can do the same in your code. By calling functions in ReportExecution2005.asmx with proper parameters, you trigger the SSRS process to render certain report for you. Actually SSRS process will run in a separate process than your main code, either in the same machine or other physical server wherever it’s installed.

Report Viewer Control on the other hand is in the same process as your main code, either it would be your ASP.NET process or your WinForm main process. Of cause you can make it fancy to spawn it into other thread, it’s all up to you.

11Q: What are the IDE tricks when using SSRS approach to develop report

A: Due to UAC and IIS 7.5’s new structure, in Windows 7 or Vista environment, you’d better start IE “run as administrator” to get it open your local PC SSRS web management  and web service URL. Even further, you might have to make sure your “localhost” is in your IE’s intranet sites list (IE\Internet Options\security\Local Intranet).

In addition, before you debug your web service calling code from Visual Studio, you’d better start VS in “run as administrator” mode. Otherwise, you will always get error like “The permissions granted to user are insufficient for performing this operation”.

Report viewer control doesn’t need this trick if it’s not connecting to SSRS.

12Q: When to use SSRS and when to use Report Viewer Control to render PDF

A: It depends (as usual). Winking smile

Reporting Viewer Control + RDLC is simple and easy to program with. Especially if you are a one-man-show for a reporting project, this is the way to go. Reporting Viewer Control can open either RDLC saved in the file system or RDL saved in SSRS database.

On the other hand, SSRS is much more complicated: you need multitier configuration/setup, believe me, it’s not trivial work.

However, SSRS makes sense if your company need to host many (tens or hundreds) RDLs as report templates for different departments, usually a DBA or even a dedicated team is assigned to maintain all the enterprise level RDLs. The DBA or team will take care of security access, data source connections and even delivery or scheduled rendering parts.

Programmer at this point just need to call the SSRS web service (by passing the proper parameters and security tokens) to render the reports based on RDLs. This can be either midnight job rendering thousands data driven PDFs or individual user click the button rendering just one PDF for him on the fly.

Both solutions can render thousands PDFs on the fly no problem. So it’s really depends on your infrastructure and project needs.

=============FAQ End========================

At the end, I still have to emphasize it one more time, configuring SSRS development environment is not a trivial effort. So if you feel frustrated, don’t blame yourself, go MSDN to find out.

Here are the source code:

====Following zip is for Reporting Viewer Control approach=====

NOTE: Report Viewer Control Library needed locally, the link is at above FAQ's 1Q

ReportViewer2Pdf.zip (22.68 kb)(VS 2010 + .NET 4.0 + Report Viewer Control)


====Following two zips are for SSRS approach=====

NOTE: SSRS installation is not covered in this article

NOTE: Business Intelligence Studio is needed for RDL, see above FAQ's 8Q

Ssrs2Pdf.zip (25.74 kb)(VS 2010 + .NET 4.0 + SSRS configuration)

Ssrs2Pdf_Rdl.zip (7.85 kb) (VS 2008 + Business Intelligence Studio)

Comments are closed