Blue Theme Orange Theme Green Theme Red Theme
 
MindFusion's Components
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
World Class ASP.NET Hosting - 3 Month Free Hosting, Click Here!
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Reporting Services » Custom Assembly in Reporting Services

Custom Assembly in Reporting Services

This article describes a problem that occurs when you access a custom assembly in your Reporting Services report that does not have sufficient permissions on the resources in your environment. The article also provides simple steps to grant permissions to the custom assemblies that are used in the reports.

Technologies: .NET 1.0/1.1, Crystal Reports,Visual C# .NET
Total downloads :
Total page views :  38472
Rating :
 5/5
This article has been rated :  1 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor



Summary

SQL Server 2000 Reporting Services is a server-based reporting solution that can deliver interactive Web-based reports. This article describes a problem that occurs when you access a custom assembly in your Reporting Services report that does not have sufficient permissions on the resources in your environment. The article also provides simple steps to grant permissions to the custom assemblies that are used in the reports.

Introduction

After you create a Microsoft .NET custom assembly and then you access the custom assembly in your report and preview the report in Report Designer mode, the report will render successfully. However, if you run the same report in DebugLocal mode in the VS IDE or if you access the report by Report Manager or Report Server or Web Interface the following error will be rendered in the report.

#Error

First let us start with creating a simple custom assembly and using it in Reports and then move to a complex one which needs permission to run successfully

Using Simple custom assembly in reporting services report

Step 1: Create a custom assembly

 

Step 2: Creating a Report

Create a Business Intelligence Project and add a Report to the project in the layout section drag and drop a text box.

Step 3: Adding an Assembly Reference to a Report

Right click the report designer area and choose properties and select the References tab and browse and select the custom dll from the location.

 

Step 4: Using Custom assembly in Reports

In order to use your custom code in your assembly in a report expression, you must call the member of a class within the assembly. This will be done differently depending on how the method was declared.

If the method is defined as static it is available globally within the report. You access it by namespace, class, and method name

=SimpleDLL.SimpleClass.returnString()

Step 5: Writing expression to the text box

Come back to Report layout tab and now right click the textbox and choose expression and enter the expression.

 

 

Step 6: Copying DLL to Report Designer and Report Server folders

Before previewing or deploying you need to deploy your custom assemblies to the application bin folders.

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

Step 7: Preview Report and deploying report


 
Now you can deploy the report to the report server and view it in the browser. To deploy the report, right click the report and choose deploy, before deploying set the target folder in the project properties.

Using Complex custom assembly in reporting services report

So far we have seen simple custom assembly in reports, now if you actually want to do something interesting like fetch data from a text file or database or use web services or registry access then we need to modify the report server policy config file and Assert permissions in your custom assembly.

Here are the steps to do that.

Step 1: Assert Permission

You must assert the required permissions in your custom assembly code, for example if you access a text file in your custom assembly then you need to add the following code to the custom assembly and add

using System.Security.Permissions.

FileIOPermission fileReadPerm = new FileIOPermission (FileIOPermissionAccess.Read, "C:\SampleFile"); fileReadPerm.Assert();

 
   

Step 2: Mark the custom assembly with the AllowPartiallyTrustedCallersAttribute

Mark the custom assembly with the AllowPartiallyTrustedCallersAttribute. This is required because custom assemblies are called from a report expression that is a part of the report expression host assembly, which by default is not granted FullTrust, thus is a 'partially trusted' caller. You can do this in your assembly attribute file AssemblyInfo.cs in C# before doing this add

using System. Security

 

Now compile the project and copy the dll to the following folders

C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin.
C:\Program Files\Microsoft SQL Server\80\Tools\Report Designer.

Step 3: Adding an Assembly Reference to a Report and View the Report

Remove the existing reference of the assembly and add the new reference to the report  and then view the report in the Preview window, you will see the data from the text file displayed.

 

Step 4: View Report in Debug local mode

Now when you view the report in DebugLocal mode now, instead of see the text from the text file you will see a message #Error in the text box. To switch to debuglocal mode just change the mode of execution to DebugLocal and right click Project properties and set the StartItem with the report you want to debug.

Now press F5, you will see this message in the screen.

 

If you preview the report in Report Designer, the report runs all the report expressions by using the FullTrust permission set. The report does not use the security policy settings. But when you run the report in DebugLocal mode or deploy report to the report server and view it in report manager you will receive the message #Error, This problem may occur when the custom assemblies that are referenced in your report do not have sufficient permission

Step 5: Code Access Security settings for your Custom Assembly

We need to modify the report server policy configuration files in order to grant the custom assembly the required permissions.

Open the rssrvpolicy.config file in the C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer folder

Note: Before making a change to the config file it is recommended making a backup copy of the original file

In the config file we need to add the code group we can add the following code. We have to place this under the correct CodeGroup node in order to work correctly. So you will need to put it under the last code group.

<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyCustomAssemblyCodeGroup"
Description="A special code group for my custom assembly.">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\Simple.dll"/>
</CodeGroup>           

rssrvpolicy.config

 

Step 6: View Report with Data

Now when you run the report in DebugLocal mode and you will see the data from the text file, before executing the report, restart the Report Server service.

Conclusion

This article provides the steps to use custom assembly in Reports. Now you should have a basic understanding of how to use custom code with reporting services.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Balaji K
I am Balaji, currently working as Application Developer in Intel Technologies, Bangalore. I am working on Reporting Services for the past 9 months and my area of expertise includes C#, SQL Server 2000, Reporting Services.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Powerful ASP.NET Hosting w/ NO Setup Fees. Click Here!
Become a Sponsor
 Comments
How to pass the parameters to dataset by custom assemblies? by nitin On July 16, 2007
I'm using the class library to pass the values to repoting services.. My custom assembly contains the multiple queries.. I want to pass the multiple parameter to dataset of reporting services by custom assemblies.. How can i pass the parameters to dataset? Please help me to solve this?
Reply | Email | Delete | Modify | 
Re: How to pass the parameters to dataset by custom assemblies? by Mario On October 23, 2007
Hello!
I am with the same problem here. Found the solution for this?

 

 

Reply | Email | Delete | Modify | 
Using reference library that involve contextinfo by kh On May 20, 2009
I had a reference library added into the custom assembly. I've asserted the permissions required for a number of methods used in the code. When running the report in preview mode it is fine but running it in debuglocal mode it returns an error due to a PSLibrary.PSContextInfo.SerializeToString(contextinfo) function as follows:
Message: Request failed.
Exception Type: 0cham2yl
Source: System.Security.SecurityException
StrackTrace:
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPSContextInfo.Write2_PSContextInfo(String n, String ns, PSContextInfo o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPSContextInfo.Write3_psci(Object o)
TargetSite: Void Write2_PSContextInfo(System.String, System.String, Microsoft.Office.Project.Server.Library.PSContextInfo, Boolean, Boolean).

Any idea how I could resolve this?
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved