Figure 1:-Crystal Report Template
Figure 1:-Crystal Report Template
This Interview Questions will give you a quick start for two report giant's crystal and reporting
services.
If you find this article useful or you think I need improvements please send me a message at
http://www.questpond.com/ . I will definitely consider your suggestions for better improvements.
Report designer gives a graphical interface to create and modify reports. To view the designer
add a new crystal report file and double click on it you should see the report designer as shown
in figure 'Report designer'.
Reports engine does the formatting and conversion part of crystal reports. It helps convert the
contents of reports in word, excel, PDF, HTML and other formats. Report viewers are controls
which you can see on the visual studio tool box; you can drag and drop those controls on an
ASPX page or windows application to view reports made using crystal. Object models help us
manage crystal reports objects during design time and run time.
Step 4 a Right click on 'Database fields' on the field explorer a then click on database expert a
Expand create new connection a Expand OLE DB ADO a Select Microsoft OLEDB provider for
SQL Server ( this depends on what kind of data you want to connect ) a Give the server
credentials a Click finish and done.
Step5 a Right click on 'Database fields' on the field explorer a then click on database expert a
Expand the server , database and select table which you want to add to the report. Below figure
'Table added in reports' shows the right pane showing the table added using database expert.
Step 6 a Expand database fields a table ( in this case it is 'FactCurrencyRate' table). Now you can
drag and drop the fields on the report.
Step 7 a We now need to display the report on the ASPX page. For that we need the
'CrystalReportViewer' control. So expand the crystal reports section of the toolbar and drag the
component on the ASPX page
Step 8:- Now we need to go to code behind and specify the report source. That's it now compile
and run the project you can see your report live in action.
Right click on the 'RPT' file and click 'Publish as web service' as shown in figure 'Publish crystal
as web service'.
Figure 11 : - Export
Second option is through coding. Below is a simple code snippet which shows how we can
export a report. Create a object of the crystal report and call the 'ExportToDisk' method
specifying in which format you want to export.
Report.PrintOptions.PrinterName = "MyPrinter"
Report.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4
Report.PrintOptions.PaperOrientation =
CrystalDecisions.Shared.PaperOrientation.Landscape
Report.PrintToPrinter(1, True, 1, 3)
manipulate data as per the report format. Below figure 'Three pass method' shows how the
parsing happens. Let's understand the same step by step. In Pre-Pass1 crystal report engine
evaluates constants like x=1 and pie=3.14 for a report. Pass 1 does two important things get data
from the database and sort records with given conditions. Once this is done it's saved in memory
and given to pre-pass2 for further parsing and manipulation. Pre-pass2 is all about grouping and
sorting the records according to conditions specified in the crystal report. Pass 2 formats a report,
applies condition and groups them. Pass 3 is the final tunnel it just counts the pages and
generates reports.
Reporting services is mainly used to generate reports. Below are the main components of
reporting services as shown in figure 'Reporting Services Architecture'. Reporting services has
four major components Client, Web services, report server/manager and reporting services
database. Let's understand all the major components and the sub components of the same.
Client: - These are the consumers of reporting services functionality. It can be the report
manager or report server (we will discuss report server and manager in more details further) or
ASPX and windows application.
Reporting Web service: - Microsoft chose XML to expose the functionality of reporting
services. So all the functionality is exposed through web services. One of the most important
gains for a web service is that it can be platform independent.
Report server / manager: - Report server and manager forms the core engine of reporting
services. They two important systems one is 'Report processor' and the other is
'Scheduling and Delivery processor'. Reporting processor is the main driver to deliver reports.
They take request from the end user and process the report and send it to the end client. Figure
'Report Processor' shows how the flow moves. We have seven basic steps which can help us
understand in more detail how the report processor works. Step 1 a Any client like ASPX or
windows application will request to the web service for reports. Step 2 and 3 a Web service will
forward the request to the report processor and get the report definition from the report server
DB. Step 4 a Reporting services uses the security extensions to authenticate the end user. Step
5 a Data processing extension calls queries the application database to get data. With data
processing extension we can connect to standard data sources like SQL Server, ODBC, Oracle
etc. You can also extend the data processing extension to adapt it to some custom data
processing extension. Step 6 a Rendering extension then renders the report applies format and
sends the same to the end client. Using rendering extension you can deliver reports in Excel,
PDF, HTML, CSV and XML. You can also extend the rendering extension to deliver in custom
formats.
The second system is 'Scheduling and Delivery processor'. Delivery extensions makes reports
with the specified format and sends the same to an output target like file, email, FTP etc.
Scheduling and delivery processor does two important steps schedules reports and delivers them
the same to a output like FTP,Email etc. Schedule and delivery processor using delivery
extension to deliver reports to the defined output. So users can subscribe to the reports and
depending on these subscriptions the delivery is done by schedule and delivery processor. There
are two steps in this one is the subscription process and the other is deliver process. Lets first try
to understand the subscription process. There are three steps basically:Step 1 a First is the requests a subscription to the report.
Step 2a This subscription is then stored in the report server DB.
Step 3 a A new SQL Server agent is created for this subscription. So we have completed the
subscription process.
Now that the subscription is created lets see how the delivery process works. Here are five basic
steps in delivery process. Step 1 a When the event occurs SQL Server agent makes an entry in
the report server DB. Step 2 and 3 a RS windows service keeps polling SQL Server for any
events. If a event has occurred it gets the event from the database and sends a message to the
'Scheduling and Delivery Processor'. Step 4 a The report is then processed by the report
processor and sent to the delivery extension who finally delivers it on a output which can be a
Reporting Services Database:- When you install reporting services you will see two databases
'ReportServer' and 'ReportServerTempDB'.'ReportServer' database contains report definitions,
schedule, subscriptions, security details and snapshots. 'ReportServerTempDB' stores temporary
information like session state about reports which is needed in between HTTP requests and
report cache information. Please note snapshots are stored in reportserver and not in
tempDB.
Introduction
This FAQ will give you a quick start for two report giant's crystal and reporting services.
If you find this article useful or you think I need improvements please send me a message at
http://www.questpond.com/.
I will definitely consider your suggestions for better improvements.
When you install reporting services there are two virtual directories created as shown in the
figure below.
The second virtual directory is the 'ReportServer' this helps us to use browse reports and use the
Can you explain Report definition language (RDL) file in reporting services?
RDL is an XML description of a report in reporting services. So basically the RDL file has the
XML grammar which describes a reporting services report. Below figure 'Snip of RDL file'
shows a simple snippet of a RDL file.
. When the project is created in the solution explorer you will see two folder 'Shared data
resources' ( we will come to data sources in the coming questions) and 'Reports'. Right click the
'Reports' folder and click add new reports.
. You need to give credentials in the wizard. Once done it pops up a query builder. Specify the
report query in the query builder and go next.
. Wizard then helps you to select the report type and some other features. Next , next and you
should see a RDL file in your 'Reports' folder.
. Click on the view menu and select tool box and you should be able to design the report.
. Till now we are only in the design mode of report. As said previously all reports meta-data are
stored in SQL Server database 'ReportServer'. In order that the report's meta-data gets saved in
database we need to publish the report.
. To publish the report we need to specify the IIS report path. So right click on the report project,
select properties and specify the 'TargetServerURL' property.
. Once we have specified the 'TargetServerURL' property we need to deploy the project. So right
click on project and click 'Deploy'
If we want to get the report in PDF format we need to use the 'Format' parameter.
If we want to pass parameters to the report we can do something as shown in the figure 'Pass
parameters to the report'. In this scenario we have passed the 'Category' parameter.
In this we will display which reports are present in the reporting server database. So we
use the 'ListChildren' method to get the reports from the web service and then loop to display the
same. 6 This sample code should display the reports present in the reporting service.
The above example is a sample of how to use the reporting web service. If you want to get how
many input parameters the report has we need to use 'GetReportParameters' method, if we
want to display the report we use the 'Render' function. There are many other function and
methods which we have not discussed to keep the chapter simple and to the point. Please
experiment around the reporting web service object for new methods and functions.
Reportviewer control
ASP.NET 2.0 comes with crystal report viewer control. You can drag and drop the control on the
ASPX page and set the properties. Below figure shows how the 'ReportviewerControl' looks like
and how we can set the properties to view the report.
Can you explain the difference between private and shared data sources?
Private data source is used by single report only while shared data sources are shared between
reports. As a practice it is good to have shared data source so if you want to change anything you
need to change only on one data source.
combination. Cached versions expire after particular schedule, when reports are modified,
deleted or redeployed.
What are the major differences between Crystal and SQL reporting services?
Ease of hosting reports: - Using the URL technology in RS we can host reports more easily
than in crystal report where we need to make a UI for the same.
Supporting platforms: - Crystal can run on windows, IBM and sun while RS (reporting
services) can run only on windows environment.
Client tools: - In reporting services we have Business intelligence ( BI ) and development studio
while in crystal its Report designer.
Caching: - This achieved in crystal by using cache server while in reporting services it's stored
DataType
UserId
UserName
FirstName
varchar(50)
Varchar(50)
LastName
varchar(50)
Location
varchar(50)
After completion of table creation enter some dummy data because we need to use that
data to populate reports.
Now Open visual studio and create new website after that right click on your website and
select Add new item in that select Crystal Report and click Add
After that add crystal report then it will prompt Crystal Report Gallery window in that select
blank solution and click OK
A blank report will create in our application now click on CrystalReports menu under that
select Database under that select Database Expert
After click on Database Expert now Database Expert wizard will open in that select Create
New Section >> select OLE DB (ADO) >> in that click on + sign of OLE DB (ADO)
Now select Microsoft OLE DB Provider for SQL Server and click Next (Here we can select
SQL Native client option also but sometimes during deployment if servers not contains this
native client it will throw error).
Now enter SQL Server name, username, password and required database and click Next
After enter credentials for your required database click Next then click Finish (Here for my
database I didnt set any credentials for that reason I didnt enter userid and password
details dont get confused).
After click Finish now our database loaded in OLEDB (ADO) section >> select your database
>> select dbo >> select required tables
Now open tables in that select required table and move to selected tables section and click
OK
After that Database Fields in Field Explorer populated with our required data table now drag
and drop the required fields from data table to reports Details section
Now open your Default.aspx page drag and drop CrystalReportViewer control from
Reporting tab.
Now select CrystalReportViewer and click on smart tag in right hand side and Choose new
Report Source
Whenever we click on New report source one window will open in that select crystal report
for Report Source from the available reports in dropdownlist and click OK.
After assign available report to CrystalReportViewer control check your code that would be
like this
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR"
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Crystal Report Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True"
ReportSourceID="CrystalReportSource1" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReport.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
Now run your application your report will be like this
In case your report prompt window for UserName and password before we access data in
that situation we need to set those details in code behind instead of assign crystal report to
CrystalReportViewer control
Drag and drop CrystalReportViewer control click on right side smart tag of your
CrystalReportViewer control and uncheck EnableDatabaseLogonPrompt
<Report FileName="CrystalReport.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
Now Open your code behind file and set database connection settings and assign reports to
the control before that first add following namespaces
using System;
using CrystalDecisions.CrystalReports.Engine;
After add namespaces write the following code in page load event
C# code
Imports CrystalDecisions.CrystalReports.Engine
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim reportdocument As New ReportDocument()
reportdocument.Load(Server.MapPath("CrystalReport.rpt"))
reportdocument.SetDatabaseLogon("", "", "SureshDasari", "MySampleDB")
CrystalReportViewer1.ReportSource = reportdocument
End Sub
End Class
Now run your application and check your output that would be like this