MS SQL ReportServer : RTF Conversion Error
I am developing report using MS SQL Reporting service. In which I have a problem to display the rich-text content. For this I am using, system.windows.form: Code: Dim rtf_converter As New System.Windows.Forms.RichTextBox() rtf_converter.Rtf = input plan_text = rtf_converter.Text I am getting exception, any comments why? Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
August 2nd, 2010 5:43am

Hi Veeravendhan, The code you posted looks fine. The root cause for the error you met is that the default permission of report expressions is “Execution”, which will protect the code to running. Here are the detailed steps to convert RTF to TXT in SQL Server Reporting Services, you may go through this step by step to fix the issue. 1. Use the following custom code in the Report. The custom code includes a function named ConvertRtfToText. This function requires a parameter that is the RTF. Public Shared Function ConvertRtfToText(ByVal input As String) As String Dim returnValue As String = String.Empty Using converter As New System.Windows.Forms.RichTextBox() converter.Rtf = input.Trim returnValue = converter.Text End Using Return returnValue End Function 2. To use the above custom code function, we need to add a reference that refers to the instance “System.Windows.Forms”. Please add the reference “System.Windows.Forms” in the “Reference” tab of Report properties dialog. 3. Setup a domain account for “Execution Account” using the Reporting Services Configuration Manager. Executing the above custom code is an unattended report processing. Unattended report processing refers to any report execution process that is triggered by an event (either a schedule-driven event or data refresh event) rather than a user request. The report server uses the unattended report processing account to log on to the computer that hosts the external data source. This account is necessary because the credentials of the Report Server service account are never used to connect to other computers. 4. For security reasons, the default permission of report expressions is “Execution” which is defined in the SQL Server Reporting Service CONFIG file "rssrvpolicy.config”. If we use a custom function in the expression, and the custom function uses code like this “Using converter As New System.Windows.Forms.RichTextBox()” , the expression will require more permissions in addition to “Execution”. To provide proper execution permission, we can change the permission set of the following code groups to be “FullTrust”: <CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="Nothing"> <IMembershipCondition class="AllMembershipCondition" version="1" /> <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 class="FirstMatchCodeGroup" version="1" PermissionSetName="FullTrust" Description="This code group grants MyComputer code Execution permission. "> <IMembershipCondition class="ZoneMembershipCondition" version="1" Zone="MyComputer" /> For more information about code access security, please see: Understanding Code Access Security in Reporting Services: http://msdn.microsoft.com/en-us/library/ms155108.aspx Execution Account (Reporting Services Configuration): http://msdn.microsoft.com/en-us/library/ms181156(SQL.90).aspx If there is anything unclear, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
August 3rd, 2010 11:37pm

Hi Jinchun, I got the same error when I was doing SSRS. I would like to pop up a message box to tell user if their parameters are correct. The custom code is like Function CheckNum(NumEntered as Integer) as Boolean Dim prompt as String Dim usrResponse As MsgBoxResult prompt = "" usrResponse = MsgBoxResult.No If (NumEntered > 25 OR NumEntered < 1) Then prompt = "You entered " & Str(NumEntered) _ & ". Are you sure you want to continue?" End If If prompt <> "" Then usrResponse = MsgBox(prompt,4,"Message Box Title" ) If usrResponse = MsgBoxResult.Yes Then Return TRUE Else Return FALSE End If Else Return TRUE End If End Function While I followed your advise, I've added an execution account and I changed the permissions of report expressions as well. But unfortunately It still shows the same error. Thanks, Kevin Miao
September 1st, 2012 11:40am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics