I am trying to use my own custom assembly in my SQL Server 2005 report. I have coded and compiled the following code to produce the ReportLibrary.dll:
Imports System.Data
Imports System.Security
Public Class myClass
Public Function myFunc() As Integer
Dim value As Integer = 0
Dim permission As New SqlClient.SqlClientPermission(Permissions.PermissionState.Unrestricted)
Dim myCommand As New System.Data.SqlClient.SqlCommand()
Dim conn As New System.Data.SqlClient.SqlConnection("MY CONNECTION STRING”)
myCommand.Connection = conn
myCommand.CommandText = "MY SELECT STATEMENT"
Try
permission.Assert()
conn.Open()
value = myCommand.ExecuteScalar()
Catch
Finally
conn.Close()
End Try
Return value
End Function
End Class
I copy the .dll file to the server at location “C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin”
I then add the security in the file “C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\rssrvpolicy.config” using these lines:
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyCodeGroup"
Description="Code group for my data processing extension">
<IMembershipCondition class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin\ReportLibrary.dll"
/>
</CodeGroup>
I then open my report, and go in the Report Properties -> References. I add a reference to the file "C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin\ReportLibrary.dll". I then add the following lines in Report Properties -> Code:
Public Function getMyFunc() As Integer
dim cls as new ReportLibrary.myClass()
return cls.myFunc()
End Function
In one of my textbox in the report, I set the expression to:
=code.getMyFunc()
Now I build my report and click on preview. The report looks good. Now I press on Play to run the report from the server, and the textbox that references my custom code just shows “#error”. I have looked for 2 days for a solution on the web but none have been successful. I believe this is a security issue (maybe with the reference to System.Data.SqlClient in my custom assembly), but have not found out how to resolve it. Any help would be greatly appreciated.
Thank you
Eric Parent
This is pretty urgent, so if you know a solution please let me know.|||Hi Eric, I did almost exactly what you have and it worked fine.
In what part of rssrvpolicy.config do you insert the code group? it should go immediately after
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="SharePoint_Server_Strong_Name"
Description="This code group grants SharePoint Server code full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100AFD4A0E7724151D5DD52CB23A30DED7C0091CC01CFE94B2BCD85B3F4EEE3C4D8F6417BFF763763A996D6B2DFC1E7C29BCFB8299779DF8785CDE2C168CEEE480E570725F2468E782A9C2401302CF6DC17E119118ED2011937BAE9698357AD21E8B6DFB40475D16E87EB03C744A5D32899A0DBC596A6B2CFA1E509BE5FBD09FACF"
/>
</CodeGroup>
No comments:
Post a Comment