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
QuestionParameter Challengesmemberswninetails11 Mar '09 - 10:52 
I have a set of reports which I am integrating into my .net 2.0 application. I have figured out how to get the reportviewer working, how to set parameters and how to render the reports. I need to be able to condition some of the parameters based on a users permission access. I am using the reportviewer for the interface, this has the export, find, view report buttons, etc...
 
When the report first renders I can set parameters as I desire, but once the user changes visible parameters and clicks the View Report button my hidden parameters go back to their default value.
 
For instance I have three parameters on one report (Department,Assigned,Status). When the user chooses to execute the report, I want to programatically set the Department value and adjust the visible attribute to false, but allow the user to use the Assigned and Status as desired. This I can do visually right now - Confused | :confused: BUT when they click View Report, the Department parameter gets reset to the default value and not what I had it set to. I also can not seem to figure out how to trigger the click of the View Report button to allow me to reset the parameter value either at render or load or which ever event it should be.
 

Anyone have any suggestions? Is this an all or nothing, or can I set some parameters and allow users to set others and still use the reportviewer? I hope this makes sense... Sigh | :sigh:
GeneralSSRS Chart ControlmemberT. Ravindran12 Aug '08 - 5:15 
Hi,
I am very new to this SSRS. I am having some doubt, please clarify my doubt.
 
I am developing a report in Sql server 2005 Reporting Services. In my report initally pie chart should display the system information. On Clicking the part of this pie chart, bar chart should be displayed in the same page. Please let me know how to do this using Chart control.
GeneralAsk for username and password when calling the reportmembersammak1687 Jan '08 - 19:57 
1. From my PC, when I call my report in the ASP page using the following URL:
Report Test
 
it will show a windows dialog box asking the username and password for the machine installed with the reportserver. (not the username and password of the SQL connection). If I type in the machine's administrator username and password, it will continue to render the report.
 
(The ASP page, the reportserver and the report itself are in the same physical machine)
 
How can I bypass this dialog box ?
 
2. My ASP page require user to input some values in some fields. And then he calls the report by pressing URL in the ASP page. How can I go back to the previous page with the field values he inputted ?
QuestionHow can I gernerate PDF format report by using SQL Reporting Service dllmemberShinde Sachin15 Oct '07 - 23:08 
I am trying to develop an application which would generate a report by making use of SQL reporting service dll. I dont want to run a report through SQL reporting server.
Can it be possible if yes than guid me else give me alternate solution.

 
Sachin Shinde
GeneralWYSIWIGmemberCourtneyB20 Jul '07 - 8:01 
I'm currently using VISUAL STUDIO.NET and SQL reporting Services for the first time and I'm impressed with the tool. It is as easy as Access Reporting and laying out but more powerful. I do have one problem though. My report is not WYSIWIG or better yet, the report will look all jumbled on the report server when you view it but it prints out perfectly and if I fix it so it views nicely, it prints out differently or in a different layout. Does anyone have any suggestions on why this is happening?
 
Courtney
GeneralMultiple parametes from a Multi select listbox to Reporting servicesmembermd riyasath ali24 Feb '07 - 20:32 
Hi friends,
Iam New to Reporting services.
I have a Muliti Select Listbox in Asp.net with items as
All
Product1
Product2
Product3
When a user select all,he should get all the product report.
When a user selects Product1 and product2(since it is a multi select listbox),he should get information of Produc1 and Product2. My question is how to pass parameter when a user selects Both product1 and product2.?
Thank you in advance......
 

 

 
Md riyasath ali
GeneralNothing was displayed on web page !membernaimish_hit5 Jan '07 - 2:53 
Hi,
 
I have tried everything you described and I am able to access report on Reporting server but nothing on my web page.
 
I have set
Report path = Report Project1/InvoiceReport and
ReportServerURL = http://secpathdev01/ReportServer/
 
What should be the reason for this
 
Regards,
 
Naimish

GeneralHere's the answer to all parameter questionsmemberwOOk?es20 Dec '06 - 2:14 
Hi All,
 
Nice Articles dude.
 
I already resolve this problem last year in MSDN Forum, Can't Remember the URL. Anyway, the easiest way to pass a parameter to the report is to use the Report Viewer Control in your ASP.Net Page, but before that you need to modify first the Report Viewer Control to be able to pass the parameter.By default, the Report Viewer Control found in the SQLServer Directory in your Program Files does not support the parameters, you need to add some codes and compile the project. For those who want the MODIFIED REPORT VIEWER CONTROL plus my sample application(in VB.Net). You can contact me at gvgonong@gmail.com.Big Grin | :-D
 
Here's some example code in VB.NET.
 
Private Function GenerateReport(ByVal nStartDate As String, ByVal nEndDate As String)
 
nReportPath = lblReportPath.Text '//Return the Report Path from the Database(For Security Reason).
nServerURL = lblServerPath.Text '//Return the Server Path from the Database(For Security Reason).
 
With RepView '// The Modified Report Viewer Control.
.SetQueryParameter("StartDate", nStartDate)'// Parameter1
.SetQueryParameter("EndDate", nEndDate)'// Parameter2
.ReportPath = (nReportPath) '// ReportPath
.ServerUrl = (nServerURL) '// ServerPath
'//OPTIONAL PROPERTIES
'THIS WILL HIDE THE PARAMETERS IN THE REPORT VIEWER ITSELF!
.Parameters = Microsoft.Samples.ReportingServices.ReportViewer.multiState.False
'THIS WILL HIDE THE TOOLBAR OF THE REPORT VIEWER!
'.Toolbar = Microsoft.Samples.ReportingServices.ReportViewer.multiState.False
End With
 
End Function
 
Thanks,
 
wOOk?es
QuestionPassing Parameter from ASP.NETmemberNick Hatzis10 Oct '06 - 21:17 
I program an ASP.NET application that uses SQL Server 2005 Reporting Services.
Recently I've run into a dead end when I had to pass a parameter from an
ASP.NET page to the report. I looked over the Internet and found absolutely
nothing. I could use a little help here if someone is capable of doing that.
 
Thanks in advance,
Nick Hatzis

AnswerRe: Passing Parameter from ASP.NETmembersunil_pune21 Nov '06 - 17:31 
Hi,
To pass parameter to report try to add parameters in report it self rather from ASP.Net application.Once you Run the Report in browser Parameters list will be automatically appears.

 
Sunil S Pawar
AnswerRe: Passing Parameter from ASP.NETmembersasikanth198226 Nov '06 - 22:31 
hi ,
this is sasikanth working in gss america.
 

if ur using url access to view a report then u should append the parameters to the url string see for example:
 

http://10.0.3.53/ReportServer?%2fsasikanthreports%2fdepartments&rs%3aCommand=Render&rc:toolbar=false&Param1=2
 

 
here i appended param1 it is a parameter and in the place of 2 u can place any value.
 
try this if u hav any doubts pls feel free to contact me at paritala_sasi@yahoo.com
QuestionManaging data (Urgent)memberPlescaSorin14 Aug '06 - 19:52 
If got a stored procedure that is my datasource for a report.
i've decided to give up on details, and so my data is brought by the footer and header section(and there are some fields with sum() function). how can i constain my data to bring only the not 0 sum's from reportviewer?
and i'd like to do some sums of groups(so i'd like to sumarize only the group header, not all the details).
 
i'm trying to respect a deadline, so all the help i'll be apreciated!

 
Plesca Sorin

QuestionReport Viewermemberdreadjr7 Aug '06 - 11:05 
Is there a custom report viewer control which just displays the parameters? So i can view them then update the parameters with the user's selected values.
QuestionProblem in Updating DataSource at ReportServermemberMuhammad Ghufran18 Jul '06 - 21:11 
I have created datasource at ReportServer. Each user's report access with different database to specific datasource. Each time I update connection string of this datasource with database name.
Now if company 1 user update this datasource with dbi1 database name to see report against database. In the mean while, company 2 user update the same datasource with dbi2 database name. Now what will happen?
company 1 user will see the report data of dbi1 or dbi2.
Does datasource instance are different for both users?

 
In the race for excellence, there is no finish line.
GeneralProblem with ParamtersmemberTushar Kothari17 Jul '06 - 0:12 
Hi
 
My application is calling report with one string parameter which have lengh of 9036 charactors. So that my report is not displying antthing in my browser.
 
So please can you help me out for this problem.....
 
Can we pass dataset from ASP.Net application to SQL Reporting service and if yes then how we can use those dataset in parameters...
 
Thanks
 
Tushar
 
Tushar kothari

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

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