Sonic Soul
Sonic Soul

Reputation: 24919

SSRS External Assembly: SecurityPermission in Preview Pane?

ok.. spent 3 days with this, learned a lot about this issue, but still can't quite get around it.

I have a SSRS Report, that references external assembly which connects to sql server, and while previewing this report in Visual Studio, i get the following exception:

SecurityException: Request for the permission of type SqlClientPermission failed

so, i added this code:

new SqlClientPermission(PermissionState.Unrestricted).Assert();

but this in turn causes this exception:

SecurityException: Request for permission of type SecurityPermission failed

The zone of the assembly that failed was: MyComputer

from what i've read, this problem should not occur in visual studio preview pane, because code should run in full trust?

Never the less, i went ahead and followed all of the instructions here, in order to give my assembly full trust. I tried adding it by URL, and by Strong Name.

<CodeGroup class="UnionCodeGroup"
   version="1"
   PermissionSetName="FullTrust"
   Name="MyNewCodeGroup">
   <IMembershipCondition class="UrlMembershipCondition"
      version="1"
      Url="C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\MyAssembly.dll"/>
</CodeGroup>

I also saw this post, and tried putting my code group in the place suggested there.

Furthermore, i tried signing my assembly, and adding a CodeGroup based on strong name (also in My_Computer_Zone.

I also tried using caspol.exe with:

caspol -af myassembly.dll

So, i think myassembly runs in full trust (although not 100% sure). I can't figure out why, i still get these permission errors from Visual Studio Preview pane.

What exactly is needed for my code to be able to Assert that sql permission?

UPDATE

i set up a local instance of SSRS server. i can deploy my report there, and it works (since i already added full trust for it), but it STILL won't work in VS. This is a temporary work around, but it sucks for development because it takes long to deploy and eats up a ton of ram..

Upvotes: 4

Views: 3417

Answers (2)

femseks
femseks

Reputation: 2964

I had to make two changes in RsPreviewPolicy.config (on the development machine):

<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. ">
</CodeGroup>
<CodeGroup
        class="FirstMatchCodeGroup"
        version="1"
        PermissionSetName="FullTrust"
        Description="This code group grants MyComputer code Execution permission. ">
  <IMembershipCondition
      class="ZoneMembershipCondition"
      version="1"
      Zone="MyComputer" />
</CodeGroup>

I hope this helps someone.

Upvotes: 4

Liam
Liam

Reputation: 1317

Sonic,

This fixed it for me but I'm guessing that your issue may be down to something else

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\RSPreviewPolicy.config

[or alternatively C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\RSPreviewPolicy.config]

                        <CodeGroup
                            class="FirstMatchCodeGroup"
                            version="1"
                            PermissionSetName="FullTrust"
                            Name="  my CustomAssemblyCodeGroup"
                            Description="A special code group for my Report custom assembly.">
                            <IMembershipCondition
                            class="UrlMembershipCondition"
                            version="1"
                            Url="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\my.ReportUtils.dll"/>
                        </CodeGroup>

The url value was initially set to the wrong folder

Url="C:\Program Files\Microsoft SQL Server\MSRS11.SQLSERVER2012\Reporting Services\ReportServer\bin\my.ReportUtils.resources.dll"/>

instead of the folder that contains the RSPreviewPolicy.config file and dlls

Even though the same dlls were in both locations it would not work

Silly on my behalf really

Liam

Upvotes: 1

Related Questions