Click here to Skip to main content
Click here to Skip to main content

Creating Reports with SQL Reporting Service and Visual Studio .NET

By , 9 May 2004
 

Introduction

The following article will give you a quick start on how to use the new reporting service of Microsoft inside your ASP.NET Application. It is relatively very easy to use reporting services, however it is a bit different from what we are used to in Crystal reports.

Background

Reporting service is basically a reporting server that uses SQL server as its backend database, all reports are deployed on the reporting server and from their you can access any reports you have access rights to. The basic idea is to have a single location where all reports are deployed, and provides a single point of access, this created a very flexible environment to deploy your reports over the enterprise. The idea is a very similar to Crystal Reports Enterprise Reporting.

Requirements:

You will need the following tools before installing the reporting service, those tools are needed for development of reports for deployment you will need exactly the same environment without Visual Studio .NET

  • SQL Server 2000 with SP3
  • IIS 5.0 or 6.0
  • Visual Studio .NET

Accessing Report Server Management Interface:

You can start by accessing your reporting service by going to http://localhost/reports this is where you can manage your reporting service. You can view reports and other information directly from this web interface, manage subscriptions, security, data sources and other. Mostly we won't be using it in this article except for viewing reports.

The Reporting Service Web Management provides browsing folders that contain reports, data source names that you have deployed. This tool provides viewing of reports, however for developing reports you must have Visual Studio .NET

The above figure shows the report server windows service, as you can see it must be running to be able to access, view and deploy reports from your development tool

As I write this article I heard from Microsoft that they have bought a tool that can provide creating reports directly from the reporting service web interface, I do not have any information when it will be released but hopefully soon.

Developing Your Own Reports

1. Creating Your First Report

First you create a new project, and select Report Project this will create a reporting service project. From here you will find two folders shared data sources, and reports. Shared data sources is one very interesting feature, this is where your data source for your reports. You can have more than 1 shared data source or even a single data source for every report, however it wouldn't be a good idea to repeat the same data source twice if you are using the same database.

2. Creating a Shared Data Source

Here just create a shared data source selecting your SQL server, Northwind database, we will be using basically the Northwind database to build a very simple report to list all our customers.

3. Selecting Data

Before selecting the data for your report, just click on new report and choose the wizard, it will take you step by step. First select the data source that you have just created, then select the table, choose any table you like, in this example I chose the customer table. Then select tabular, and then select all data fields into the detail list box. After you are done, go to the Data Tab of your report you will find table customer, with all fields select here you can alter the table or fields you want to select in your report, just as you are used to when creating a view in SQL Server.

4. Selecting Design

After you are done selecting the data go to, report designer select the layout tab in your report, as you can see in the left toolbox you can use any of the report control to enhance your report functionality and design. You can include charts, images, matrix, etc.. after you're done lets preview the report.

5. Previewing Report

One of the features I love about the reporting service, is the ability to preview your report before deployment, here you can view your report as if you are in the deployment environment.

6. Deploying Report on Report Service

The deployment part is tricky now, you do not just include a reporting customer control in your ASP.NET page and that's it, well you have to first deploy them on your reporting service Server. Ok now as we said all your reports are developed on Visual Studio .NET then they are deploying to a reporting server, either on your machine, intranet, or internet anywhere you want them as long you have access rights to that reporting server. To start deployment right click your application and select properties, the following window will appear. You will find the property "OverwriteDataSources" to be false, make it to true, then select the target folder, this can be anything you like. Then enter the location of your reporting server here it is localhost however it can be a domain, IP address or any location you want as long as reporting service is installed to it. After you are done press F5 or right click the project and select deploy, the minute this is done your reports are deployed on your reporting server.

7. Viewing Report from Report Service

As I said now your report is deployed on the reporting server you can access it directly by going to http://localhost/reports , select the folder you installed the report in then select your report. The report should appear like the one shown below:

8. Including ReportViewer Custom Control in your ASP.NET Application

Now the tricky part on how to include this report in your ASP.NET application, here you will need to use a custom control however, Microsoft does not provide a custom control like crystal report viewer custom control, in fact you will find it deployed in the samples directory of Reporting service. The custom control is located at

C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\Samples\Applications\ReportViewer

You can just go and open that project and compile it and use the ReportViewer DLL in your ASP.NET application. This can be done by opening your toolbox, then click Add/remove and click browse and select the ReportViewer.DLL I included the source and the DLL in the source in case you cannot find it or you didn't install the sample applications of reporting service. Anyway after selecting the DLL you have to select the custom control from the list as shown below:

You will find the name of the Custom Control ReportViewer "Microsoft Sample Report Viewer Application"

When you are done, just include the custom control in your ASP.NET page and change the following properties.

  • First you have to select the report path and this should be something like :- My Reports/Report1 - exactly the sample folder you deployed your reports in.
  • Second you have to edit the ServerURL and here you enter your reporting service location http://localhost/reportserver/ this is the reporting server location, while /reports is the report server web management so take care not to get mixed up.

Once both are done, you can start viewing your report by accessing your ASP.NET web page.

9. Viewing your ASP.NET Application, including your Report

Now enter the location of your web application and choose the asp.net page that contains the custom control, and bingo here you find your report as shown below. See how easy

Conclusion

Now you can create as much reports as you want and use the custom control to view them by just changing their reportpath this can be done at runtime. If you need any extra help email me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Akram Hussein
Egypt Egypt
Member
Software Development Manager / Architect.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionnicememberspark4future18 Feb '13 - 23:50 
very nice article
spark(abdul Gaffar)

GeneralMy vote of 5membermuhammad hafizi3 Dec '12 - 14:38 
nice
GeneralMy vote of 5memberyusra_764425 Nov '12 - 19:16 
It help alot...Thanks Akram..
GeneralMy vote of 4memberpradiprenushe26 Aug '12 - 21:28 
Easy to unserstand
QuestionRegarding Custom Templatememberanup srivastava15 Jul '12 - 22:02 
I had SSRS custom template that i need to use in .net web application and from that application user can login and then pick one of the template and then design the report. so my question is how user can get the ssrs custom template and how the user can design the report on the report designer. Can we provide any kind of customized report designer tool to user or how we can achieve this. Kindly respond.
 
Thanks
GeneralMy vote of 5memberaofeng310 Jul '12 - 20:20 
thanks i like
Questionmultiple page reportmemberethan hawlke10 Jul '12 - 5:50 
i'm using vs2008, how does one create a two page report with the same headings at the top of both pages. this report will be printed for multiple customers with the customer name changing on page 1 of the two page report.
QuestionhimemberGaurav Vohra7 Aug '11 - 20:22 
hi
 
i have two machines on Machine-A SqlServer is located and on Machine-B visual studio is located. now i created one report on Machine-A and deployed it. Now I want to access the same report on Machine-B. But I m not able to access it.
QuestionTrying to set report path in reportviewer propertiesmembermazer24229 Jul '11 - 14:54 
Hi,
Thank you for your input. I have an old version of SSRS and VS 2003. This is the first time that I've tried to use the sample reportviewer control and I must admit I'm a bit at sea. I am getting errors setting my report path in the properties box. I can find the server (remote) and reportserver, but not the reports. The url they generate are http://reportserver/reports but when I try to put /reports as the path I get an error.
Also, my next task will be to pass parms in the codebehind that won't be visible to the end user. I want all of the other functions of the reportviewer however. Just parms and security will be in the codebehind. Do you have any sample code that passes parms to the reportviewer object?
Thanks so much!
Joyce
GeneralHandy reporting softwarememberiamjtsjl5 Jan '11 - 5:10 
Why guys still use this type of coding.. move on to ready made Reporting software's like Windward Reports. Its easy to use very flexible and it provides full enterprize level reporting and document generation. The Windword also supports various layout tool such as Microsoft word, excel and power point. the very important thing is the Template design, you can generate template designs within a matter of time and vey easy and will create designs that no other software will do.
 
For more details, Please click Sql Server Reporting

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 10 May 2004
Article Copyright 2004 by Akram Hussein
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid