http://www.sqlservercentral.com/blogs/dknight/2012/01/26/ssrs-custom-code-with-external-assemblies/

Printed 2014/12/22 11:32AM

SSRS - Custom Code with External Assemblies

2012/01/26

In a previous post I wrote about how you can use embedded custom code to extend the capabilities of Reporting Services.  This week I will show you another method of using custom code but this time with external assemblies.  Ideally when using custom code you would choose to do so using external assemblies.  External assemblies help developers manage code from outside Reporting Services and share the exact same code across multiple report.  Here’s a few of the pros and cons of using external assemblies for custom code.

Pros

Cons

In this example I’m going to walk you through beginning to end of an example of how to create an external assembly then use it in Reporting Services.  Our goal is to compartmentalize our code into and assembly so every developer does an age calculation the same way.  Calculating age can easily be done in the expression language the Reporting Services provides but using the assembly assures It’s done the exact same way every time.  These steps will walk you through:

  1. Creating an assembly with VB.Net (could be done with C# as well)
  2. Signing the assembly with a strong name.  This must be done because an assembly is deployed to the Global Assembly Cache (GAC)
  3. Provide the proper permissions to the assembly so Reporting services can use it with the <Assembly: AllowPartiallyTrustedCallers()> declaration
  4. Deploying the assembly to Reporting Services and the GAC
  5. Using the Assembly in Reporting Services.

Creating an External Assembly

image

Public Class Age

Public Shared Function CalculateAge(ByVal BirthDate As Date) As Integer

Return DateDiff("yyyy", BirthDate, DateTime.Now())

End Function

End Class

image

image

image

image

image

image

I hoped this step by step helps.  If this topic is something that interest you then you may also be interested in a SSRS Master (Advanced) Class I’m teaching.  You can find when the next one is here.


Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.