Sunday, March 25, 2012

Access COM+ component through embedded code

I am trying to access a COM+ component through embedded code of my
report. I added the reference to my COM+ component and a reference to
EnterpriseServices in the report. I also added the following to
rssrvpolicy.config:
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="GPATS_BO"
Description="This code group grants permissions to
GPATS_BO.dll full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="<value>"
/>
</CodeGroup>
I also added the following line to my assembly:
<Assembly: System.Security.AllowPartiallyTrustedCallers()>
Here is the function that I am trying to call:
<System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert,
Unrestricted:=True)> _
Public Function GetInvestmentTypeTest(ByVal partyId As Integer) As
String
Try
Return "IT WORKED"
Catch ex As Exception
Throw ex
End Try
End Function
I get the following error:
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.
at
System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type
serverType)
at
System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type
serverType, Object[] props, Boolean bNewObj)
at ReportExprHostImpl.CustomCodeProxy.GetInvestmentTypeTest(Int32
partyId)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
MyComputer
I can get the value and it uses the COM+ component when it is run in
the IDE and you preview the report. Once it is deployed and you try to
view it through the RS website, it gives the error above.
I am an admin on the machine and I even unchecked "Enforce access
checks for this application" in COM+ for this component, so permissions
really shouldn't be a problem. I also made the account that reporting
services runs under an admin on the machine and it didn't help (as I
suspected, but I had to try anyway).
I tried the same steps but with a dll not in COM+ (except I also copied
the dll into the folder "C:\Program Files\Microsoft SQL
Server\MSSQL.3\Reporting Services\ReportServer\bin\") and it works fine
both locally and when deployed.
Is it even possible for a report to use a COM+ component? The reason I
ask is that the application and the reports use many common functions.
I really don't want 2 dlls with the same code, so we are trying to make
Reporting Services use the component.Is there anyone that has tried this before? I see a few posts on the
subject, but no resolution. Thanks for any help anyone can give on
this issue.
Devin
Devin wrote:
> I am trying to access a COM+ component through embedded code of my
> report. I added the reference to my COM+ component and a reference to
> EnterpriseServices in the report. I also added the following to
> rssrvpolicy.config:
> <CodeGroup
> class="UnionCodeGroup"
> version="1"
> PermissionSetName="FullTrust"
> Name="GPATS_BO"
> Description="This code group grants permissions to
> GPATS_BO.dll full trust. ">
> <IMembershipCondition
> class="StrongNameMembershipCondition"
> version="1"
> PublicKeyBlob="<value>"
> />
> </CodeGroup>
>
> I also added the following line to my assembly:
> <Assembly: System.Security.AllowPartiallyTrustedCallers()>
>
> Here is the function that I am trying to call:
> <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert,
> Unrestricted:=True)> _
> Public Function GetInvestmentTypeTest(ByVal partyId As Integer) As
> String
> Try
> Return "IT WORKED"
> Catch ex As Exception
> Throw ex
> End Try
> End Function
>
> I get the following error:
> System.Security.SecurityException: Request for the permission of type
> 'System.Security.Permissions.SecurityPermission, mscorlib,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
> failed.
> at
> System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type
> serverType)
> at
> System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type
> serverType, Object[] props, Boolean bNewObj)
> at ReportExprHostImpl.CustomCodeProxy.GetInvestmentTypeTest(Int32
> partyId)
> The action that failed was:
> Demand
> The type of the first permission that failed was:
> System.Security.Permissions.SecurityPermission
> The Zone of the assembly that failed was:
> MyComputer
>
> I can get the value and it uses the COM+ component when it is run in
> the IDE and you preview the report. Once it is deployed and you try to
> view it through the RS website, it gives the error above.
> I am an admin on the machine and I even unchecked "Enforce access
> checks for this application" in COM+ for this component, so permissions
> really shouldn't be a problem. I also made the account that reporting
> services runs under an admin on the machine and it didn't help (as I
> suspected, but I had to try anyway).
> I tried the same steps but with a dll not in COM+ (except I also copied
> the dll into the folder "C:\Program Files\Microsoft SQL
> Server\MSSQL.3\Reporting Services\ReportServer\bin\") and it works fine
> both locally and when deployed.
> Is it even possible for a report to use a COM+ component? The reason I
> ask is that the application and the reports use many common functions.
> I really don't want 2 dlls with the same code, so we are trying to make
> Reporting Services use the component.

No comments:

Post a Comment