Answered by:

Adding System.Data to Code tab in SSRS 2008 R2

Question

I have a query/stored procedure that I want to execute via .Net in the Code tab from SSRS. For both System.Data.OleDb and System.Data.SqlClient (tried both) I need to add
System.Data to the references:

So for no problem, but when I try to execute the code I only see ﻿#Error in the field where I call my function. And I get the following error for SqlClient:

In SSRS 2005 (long time ago) it was
sufficient to ﻿set the PermissionSetName to FullTrust in the CodeGroup Report_Expressions_Default_Permissions (file:rssrvpolicy.config), but that doesn't work for 2008 R2.

Any suggestions? All the posts about Code Access Security in Reporting Services are about custom DLL's but this isn't a Custom DLL...

Based on the error message you mentioned above, the custom assembly you referred requires more permissions than the default Execution level permissions, you must make some code access security changes to enable the reporting services to call to this assembly.
So I suggest you to create a new CodeGroup for your custom assembly, and then grant full trust permissions. To do this, open the <Reporting Services Install path>\ReportServer\rssrvpolicy.config file, and then add the following code.
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyCodeGroup"
Description="Code group for my data processing extension">
<IMembershipCondition class="UrlMembershipCondition"
version="1"
Url="C:\pathtocustomassembly\customassembly.dll"
/>
</CodeGroup>

Please replace the Url path to your own assembly path. Moreover, we recommend that you create a more specific permission set instead of assigning this permission set to your code group. This example is intended to get you up and running with custom assemblies,
and this requires more detail.
More information about this topic, please refer to the articles below:
How to use custom assemblies or embedded code in Reporting Services:
http://support.microsoft.com/kb/920769
How to grant permissions to a custom assembly that is referenced in a report in Reporting Services:http://support.microsoft.com/kb/842419

An easiest way is to open the <Reporting Services Install path>\ReportServer\rssrvpolicy.config file, and then find the CodeGroup Report_Expressions_Default_Permissions, and then modify its PermissionSetName to FullTrust:
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Report_Expressions_Default_Permissions"
Description="This code group grants default permissions for code in report
expressions and Code element. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
…
After you complete the below modification, you can rerun the report in report server or report manager web site, it would work just as you expected.