You are on page 1of 6

Crystal report to SRS

Converting Crystal Report functions and constraints


to Reporting Services

Adding Constraints and Functions to SRS:


This section takes you through the steps of adding custom functions and constraints to
your report in reporting services.

Embedded code functions

To add custom functions (these can only be instance based and not static functions) to
your report go to the report menu and select report properties or right click within the
report design area. Under the code tab write the code you want to include within your
report.

Note: Only basic VB operations can be performed due to security issues.

To use this code within the report refer to the Constraints section below.

Created by: John Ilett


25/05/2011
1 of 6
Crystal report to SRS

Constraints

To add a conditional constraint to a particular cell right click on the cell and select
Expression. Alternatively click on the properties dialog box and select the colour cell
option and then select Expression. Here you can write you own constraint and add
parameters to it. The convention for calling the function is:
Code.FunctionName(Parameters)

Creating Functions within an assembly


Why create an assembly
The main advantage of creating an assembly is the fact that a single assembly can be
used across multiple reports.
An assembly allows the user to add security at a much more granular level.
1. Creating an assembly

To create a custom assembly you need to create a new class library WITHIN your
SRS Solution. This can be done in C#, VB.net, J# or any third party language that is
compatible with .net.

Then write the code for the functions in the assembly.


Created by: John Ilett
25/05/2011
2 of 6
Crystal report to SRS

Created by: John Ilett


25/05/2011
3 of 6
Crystal report to SRS

2. Referencing the assembly within your report:

On the report menu click report properties or click on the report design area. Select
the references tab:
1. In references, Click Add (…) button and browse to the assembly from the Add
References dialog box.
2. To use your custom code in your assembly in a report expression, you must
call the method of the class.
a. If your method is defined as static. You access it by namespace, class
and method name. E.g. =HealthWare.Employee.CostPerVisit(empID).
b. If the custom assembly contains instance methods you must add the
class and instance name information to the report reference. You
access the method by code member, instance and then method name.
e.g. =Code.rptHealthWare.Employee.CostPerVisit(empID).

4. Deploying your custom assembly

1. You need to deploy your custom assemblies to the application bin

o For the Report Designer the default is: C:\Program Files\Microsoft


SQL Server\80\Tools\Report Designer.
o For the Reporting Server the default is: C:\Program Files\Microsoft
SQL Server\MSSQL\Reporting Services\ReportServer\bin.

2. Next you need to edit the reporting services policy configuration file if your custom
assembly requires permissions in addition to Execution permissions:

o For the Report Designer the default location is: C:\Program


Files\Microsoft SQL Server\80\Tools\Report Designer.
o For the Reporting Server the default location is: C:\Program
Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer.

Created by: John Ilett


25/05/2011
4 of 6
Crystal report to SRS

To add permission to read a file called D:\Temp\EmployeeCost.xml you first need to


add a permission set in the policy configuration file that grants read permission to the
file that we can then apply to the custom assembly.

<PermissionSet class="NamedPermissionSet" version="1"


Name="EmpCostFilePermissionSet"
Description="Permission set that grants read access to my
employee cost file.">

<IPermission class="FileIOPermission" version="1"


Read=" D:\Temp\EmployeeCost.xml "/>
<IPermission class="SecurityPermission" version="1"
Flags="Execution, Assertion"/>
</PermissionSet>

Next we add a code group that grants our assembly the additional permissions.

<CodeGroup class="UnionCodeGroup" version="1"


PermissionSetName=" EmpCostFilePermissionSet"
Name="EmpCostCodeGroup"
Description="Employee Cost Per Visit">

<IMembershipCondition class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL
Server\MSSQL\Reporting
Services\ReportServer\bin\Employee.dll"/>
</CodeGroup>

Note : The name of your assembly that you add to the configuration file must match
exactly the name that is added to the RDL under the Code Modules element.

In order to apply custom permissions, you must also assert the permission within your
code. For example, if you want to add read-only access to an XML file
C:\CurrencyRates.xml, you must add the following code to your method:

// C#
FileIOPermission permission = new
FileIOPermission(FileIOPermissionAccess.Read,
@" D:\Temp\EmployeeCost.xml");
try
{
permission.Assert();

// Load the XML currency rates file


XmlDocument doc = new XmlDocument();
doc.Load(@"D:\Temp\EmployeeCost.xml");
...
You can also add the assertion as a method attribute:
[FileIOPermissionAttribute(SecurityAction.Assert, Read=@"
D:\Temp\EmployeeCost.xml")]

For more information, see ".NET Framework Security" in the .NET Framework
Developer's Guide.
Created by: John Ilett
25/05/2011
5 of 6
Crystal report to SRS

Important points:

1. If you modify a custom assembly you must both rebuild and then redeploy it
as the report designer only looks within the report designer folder.
2. System.Data and System.Xml assemblies must be available on both the
computer being used to design the report and the SQL reporting server when
creating a custom assembly

References:

• Altering security configuration policy:


http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/dnsql2k/html/dngrfCodeAccessSecurityInSQLServer2000ReportingService
s.asp

Created by: John Ilett


25/05/2011
6 of 6

You might also like