Feed Icon  

Contact

  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics

Tags

Open Source Projects

Archives

Ads

Writing Custom Code in SQL Server Reporting Services

Posted in Reporting Services at Friday, July 16, 2004 3:24 AM Pacific Daylight Time

Writing Custom Code in SQL Server Reporting Services

Someone asked me today how to use a Custom Assembly in Reporting Services. Since I'd never used one before I tried to point them to some useful articles that I found here on MSDN. However, the article didn't seem to help much so I decided to look into it and figure out how to do this since it is an interesting topic.

Let me start by saying that I found the documentation on this to be pretty poor. The docs (which can be found here) do you give enough information to figure it out, but they leave out the information that would make the process as simple as it should be. So that is the goal of this article, to show you how easy it really is to write custom code for SQL Server Reporting Services.

Embedded Code

For our first trick we will write some embedded code. To get started open your browser to this page. On that page under embedded code you will see the following statement.

To use code within a report, you add a code block to the report. This code block can contain multiple methods. Methods in embedded code must be written in Visual Basic .NET and must be instance based.

I'm assuming that "instance based" means the methods don't have to be shared (that's static for you C# coders). However, in my tests I found you can use either instance based or shared methods.

So let's get started and add some embedded code to a report. Fire up Visual Studio and create a new report project and a new report (Right click the project -> Add New Item -> Report). Next click this link for instuctions to add the embedded code to the report.

To add code to a report

  1. On the Report menu, click Report Properties.
  2. Note If the Report menu is not available, click within the report design area.
  3. On the Code tab, in Custom Code, type the code.


So type the code :)

It actually is that easy. So for our example type the following:

Public Function SayHello() as String
  Return "Hello from Embedded Code"
End Function

Next add a textbox to the new report put "=Code.SayHello()" without the quotes in the textbox. You should now be able to preview your report and see "Hello from Embedded Code" on the report. That is as far as we are going to take embedded code (I also found this article which talks a little more about embedded code). At this point you should be able to deploy your report to the server and run it on the server.

Custom Assemblies

The next topic is custom assemblies. This is a much more useful feature since you aren't constrained to writing code in VB.Net on a small dialog in the report designer. You can use Visual Studio and your language of choice. So for our example create a new Visual Studio Class Library project in either C# or VB.Net. Call it MyCustomAssembly. Next rename Class1 to SayHello. To the SayHello class we will add one method which is shown below.

[VB]
Public Shared Function Hello() as String
  Return "Hello from My Custom Assembly!"
End Function

[C#]
public static string Hello()
{
  return "Hello from My Custom Assembly!";
}

Once you're done with the code go ahead and compile the project. Once you've gotten your assembly compiled follow this link for instructions on how to add a reference to your code. Once you've added the reference to your code you will also need to copy the dll file to the C:\Program Files\Microsoft SQL Server\80\Tools\Report Designer folder on your computer. The dll file can be found in your project folder under the bin\debug folder (or bin\release if you compiled a release build).

Note: You only need to add a reference. The Class section will only be used if you're class has instance methods (versus Shared or static methods).

Add another textbox to your report and this time fill it with "=MyCustomAssembly.SayHello.Hello()". You should be able to preview the report and see "Hello from My Custom Assembly" on the report. So you have now used both embedded code and custom assemblies. Before you can deploy the report you need to copy the MyCustomAssembly.dll to the server and put it in the C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin folder on the server. Once you have copied the dll file you should be able to deploy your report to the server.

But what if you want to actually do something interesting like grab values from a database or use a web service? To do that you will need to modify the Code Access Security (CAS) settings for reporting services.

Code Access Security

There is actually a comprehensive article on this topic here. I would recommend you read that article. There is also a good introduction to CAS in general here and here. The goal of this article (the one you're reading) is to give you a quick-and-easy example that can get you started. So we will attempt to read a value from a file and return it.

First create a text file called hello.txt and put it in your c:\temp folder. In the file add the text "Hello from a text file!" and save and close the file. Next add the following method to your SayHello class:

[VB]
Public Shared Function HelloFromFile() as String
  Dim reader as StreamReader = New StreamReader("c:\temp\hello.txt")   Dim hello as String = reader.ReadToEnd()
  reader.Close()
  Return hello
End Function

[C#]
public static string HelloFromFile()
{
  using (StreamReader reader = new StreamReader("c:\\temp\\hello.txt"))
  {
    return reader.ReadToEnd();
  }
}

Note: You will also need to add Imports System.IO in VB and using System.IO in C#.

Next compile you the project. Once the project is compiled you will need to remove the old reference in your report and add the new reference and copy pver the new dll (you will have to close the report project to do this). Add a new textbox to the report and fill it with "=MyCustomAssembly.SayHello.HelloFromFile()". You should be able to preview the report and see the text that you added to the text file.

Next copy the dll and the text file (and put the text file in the c:\temp folder) to the server and deploy the report to the server. When you try to view the report on the server you won't see your message. Instead you should see "#Error".

In order to make this work on the server we need to follow the steps outlined in the CAS article. The first step according to the article is to:

1. Identify the exact permissions that your code needs in order to make the secured call. If this is a method that is part of a .NET Framework library, this information should be included in the method documentation.


Since we are using the StreamReader object we should be able to find this information in the StreamReader documentation but unfortunately I wasn't able to find it (at least I didn't see it). However, I'm going to guess (and I guessed right) it requires the FileIOPermission from the System.Security.Permissions namespace.

Next we need to:

2. Modify the report server policy configuration files in order to grant the custom assembly the required permissions.


So following the example given in the article on CAS we can add the following Xml under the <NamedPermissionSets> node in the rssrvpolicy.config file in the C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer folder.

Note: Be careful when you edit this file. I would highly recommend making a backup copy of the original file before making any changes. This file is an Xml file and you must be sure that what you add is valid Xml.

<PermissionSet
    class="NamedPermissionSet"
    version="1"
    Name="HelloFilePermissionSet"
    Description="A special permission set that grants read access to my hello file.">
  <IPermission
      class="FileIOPermission"
      version="1"
      Read="C:\temp\hello.txt"
  />
  <IPermission
      class="SecurityPermission"
      version="1"
      Flags="Execution, Assertion"
  />
</PermissionSet>

Next we need to add the code group. Again, based on the example in the CAS article we can add the following Xml. We have to put this under the correct CodeGroup node in order for it to work correctly. So you will need to put it under the last code group, but make sure it has the same parent node as the last code group. To do this just insert it before the second to last ending CodeGroup as shown below:

...
      />
      </CodeGroup>
[Insert Here]
    </CodeGroup>
  </CodeGroup>
</PolicyLevel>
...

Here is the code group to add.

<CodeGroup
    class="UnionCodeGroup"
    version="1"
    PermissionSetName="HelloFilePermissionSet"
    Name="MyCustomAssemblyCodeGroup"
    Description="A special code group for my custom assembly.">
  <IMembershipCondition
        class="UrlMembershipCondition"
        version="1"
        Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\MyCustomAssembly.dll"
  />
</CodeGroup>

Once you've added all this you will still need to complete steps 3 & 4 before the custom assembly will work.

3. Assert the required permissions as part of the method in which the secure call is made. This is required because the custom assembly code that is called by the report server is part of the report expression host assembly which runs with Execution by default. The Execution permission set enables code to run (execute), but not to use protected resources.

4. Mark the custom assembly with the AllowPartiallyTrustedCallersAttribute. This is required because custom assemblies are called from a report expression that is a part of the report expression host assembly, which by default is not granted FullTrust, thus is a 'partially trusted' caller. For more information, see "Using Strong Named Custom Assemblies," earlier in this document.


To complete step 3 you will need to first add using System.Security.Permissions or Imports System.Security.Permissions to your SayHello class. Next you will need to assert the FileIOPermission on the HelloFromFile method as shown below:

[VB]
<FileIOPermissionAttribute(SecurityAction.Assert, Read="c:\temp\hello.txt")> _
Public Shared Function HelloFromFile() as String
...

[C#]
[FileIOPermissionAttribute(SecurityAction.Assert, Read="c:\\temp\\hello.txt")]
public static string HelloFromFile()
...

Next in your assembly attribute file (AssemblyInfo.cs in C# or AssemblyInfo.vb in VB), add the following assembly-level attribute (and add Imports System.Security or using System.Security):

[VB]
<assembly:AllowPartiallyTrustedCallers>

[C#]
[assembly:AllowPartiallyTrustedCallers]

Once you've done this, recompile the assembly and copy it to the server. You should now be able to execute the report and see "Hello from a Text File!" instead of "#Error". If you still see the error need to make sure that you click the refesh button on the report toolbar and you may have to restart the reporting service.

That's it! Hopefully you were able to get everything to work. Now you should have a basic understanding of how to use custom code with reporting services. If you have drop leave a comment and I will try to address it.

Friday, July 16, 2004 6:03:00 AM (Pacific Daylight Time, UTC-07:00)
Nice... thanks for taking the time to blog this...
Monday, July 19, 2004 3:18:00 AM (Pacific Daylight Time, UTC-07:00)
Bryant is a Genius! Thanx B
Raffi
Monday, July 19, 2004 7:23:00 PM (Pacific Daylight Time, UTC-07:00)
Thanks Bryant - just what I needed to get start.
<br>Microsoft if you're watching - this is what we want in documentation, step by step examples.
Chris McG
Tuesday, July 20, 2004 6:31:00 AM (Pacific Daylight Time, UTC-07:00)
Could you elaborate on instance based classes and the procedures required to make this work.
<br>
<br>I ran across this "bad example"
<br>:
<br>Public shared Function AddToCount (ByVal Value As Integer) As String
<br> Count = Count + value
<br>End Function
<br>Shared Count As Integer=0
<br>
<br>It was considered a "bad example" because multiple users would be changing the same Count field.
<br>
<br>What would be a working "good example" of this using instance based functions and using the Reference Tab and the Class/Instance section in RS?
<br>
<br>I have seen many examples using static functions and step by step instructions. I have not found a single example yet of a working instance based custom assembly walk through anywhere. :(
<br>
<br>Would appreciate it if you could take a look at this and extend your blog to cover this case step by step.
<br>
<br>Thanks for the guidance. I just think the community needs more input on instance based data manipulation with custom assemblies. Instead of static functions.
<br>
<br>Once we actually know how to implement a instance based solution we can discuss when and where to use it but I'm still stuck on implementation. :(
<br>
Sidney
Tuesday, July 20, 2004 11:38:00 AM (Pacific Daylight Time, UTC-07:00)
Sidney,
<br>
<br>What are you trying to accomplish that requires a stateful object? There are ways you could do this but they would probably have some high overhead.
<br>
<br>
Wednesday, July 21, 2004 1:45:00 AM (Pacific Daylight Time, UTC-07:00)
Well the question was fairly generic-I simply don't know how to implement an instance based function into RS. I don't know what elements have to line up on the code in the VB to fit with what you select/enter on the RS side.
<br>I've not seen 1 step by step example on connecting the dots between the name of the assemblie/namespace/class name/function name to what you enter in the RS property reference tab.
<br>
<br>One specific question i have in mind:
<br>Assume data in Groups
<br>Within a group you have a column of string values-Say states for example
<br>on a group summary line you want a concatenation of the string state values for all rows in the group.
<br>so you might have
<br>ID State
<br>1 AZ
<br>1 AL
<br>1 MO
<br>
<br>Summary group footer:
<br>1 AZ, AL, MO
<br>
<br>This is a little similar to the "running total" idea but instead of adding values I want to concatenate strings togather.
<br>
<br>Any suggestions.
<br>
<br>But beyond resolving this need, I need to understand generally how to use instance based functions in RS. So please don't try to answer the need behind the need when I really need to nail down how to design ANY instance based custom assembly and line it up with RS.
<br>
<br>Thanks.
Sidney
Wednesday, July 21, 2004 3:32:00 AM (Pacific Daylight Time, UTC-07:00)
Ok. I've played with this a little and it seems to work fine. I'll post an update.
Wednesday, July 21, 2004 5:04:00 AM (Pacific Daylight Time, UTC-07:00)
I am trying to access a database through a custom assembly and I already have the following in the rssrvpolicy.config file , but I still get the #Error.
<br><CodeGroup
<br> class="UnionCodeGroup"
<br> version="1"
<br> Name="MySecurityExtensionCodeGroup"
<br> Description="Code Group for Don's test security extension"
<br> PermissionSetName="FullTrust">
<br> <IMembershipCondition
<br> class="UrlMembershipCondition"
<br> version="1"
<br> Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting
<br>Services\ReportServer\bin\MyAssembly.dll"
<br> />
<br></CodeGroup>
<br>Do I need an associated permission set? And what would that be if I do, I dont know?
<br>
<br>And do I need to do step 3 and 4 of your article for my custom assembly if I am only accessing a database from my function.
<br>And If I do, what would step 3 and 4 be?
<br>
<br>
Don
Wednesday, July 21, 2004 8:52:00 AM (Pacific Daylight Time, UTC-07:00)
To person trying to acccess database:
<br>you need to add a different permission set class than the file/IO one in Bryant's blog or the UrlMembershipCondition in yours.
<br>Try this one:
<br>class =SqlClientPermission
<br>
<br>You also need to see books online: Asserting Permissions in Custom Assemblies
<br>
<br>From MSFT post on forum:
<br>You need
<br>to assert security permissions inside the custom assembly. Every call that
<br>requires certain permissions (e.g. opening a database connection) will fail
<br>unless the required security permissions for that call (documented in MSDN)
<br>have been asserted.
<br>
<br>Example for opening a connection to a SQL Server:
<br>
<br> ...
<br> SqlClientPermission permission = new
<br>SqlClientPermission(PermissionState.Unrestricted);
<br> try
<br> {
<br> permission.Assert(); // Assert security permission!
<br> SqlConnection con = new SqlConnection("...");
<br> con.Open();
<br> ...
<br> }
<br>
<br>
<br>You might also want to check out these links:
<br><a target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_rdl_0so6.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_rdl_0so6.asp</a>
<br><a target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAssert.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAssert.asp</a>
<br><a target="_new" href="http://msdn.microsoft.com/library/en-us/RSPROG/htm/rsp_prog_rdl_8wyq.asp">http://msdn.microsoft.com/library/en-us/RSPROG/htm/rsp_prog_rdl_8wyq.asp</a>
<br>
<br>--
<br>This posting is provided "AS IS" with no warranties, and confers no rights.
<br>
Sidney
Wednesday, July 21, 2004 8:58:00 AM (Pacific Daylight Time, UTC-07:00)
Oops Sorry I didn't notice this was answered already. Bryant's responsiveness is out of this world. :)
Sidney
Wednesday, July 21, 2004 8:58:00 AM (Pacific Daylight Time, UTC-07:00)
Oops Sorry I didn't notice this was answered already. Bryant's responsiveness is out of this world. :)
Sidney
Friday, July 23, 2004 3:40:00 AM (Pacific Daylight Time, UTC-07:00)
I'm a recent college grad doing some asp.net. I'm writing a webpart which I want to access a SQLServer, but I get this error:
<br>
<br>"Request for the permission of type System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed."
<br>
<br>I read the Lamont post and added this:
<br>
<br> <SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<br>
<br>and this:
<br>
<br><IPermission class="SqlClientPermission"
<br>version="1"
<br>Unrestricted="true"
<br>/>
<br>
<br>
<br>to my wss_mediumtrust.config, and minimaltrust files.
<br>
<br>However this did not work. I got an error saying:
<br>
<br>A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.
<br>
<br>Before I ever made the config file changes, I also made a strongname for my NewWebPart.dll file, and I thought I took care of the "not registered as safe" problem.
<br>
<br>Could it be that I should use my own key instead of the b77a5c5....? I tried using the one I have for the .dll file, but that didn't seem to work either.
<br>
<br>Does anyone have a solution? I'm a new programmer and I don't understand what I'm doing.
Friday, July 23, 2004 5:21:00 AM (Pacific Daylight Time, UTC-07:00)
I am getting the same error Jesse,
<br>
<br>The value expression for the textbox ‘xxxxx' contains an error: Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
<br>
<br>Still looking into it.
<br>
<br>Don
Don
Monday, July 26, 2004 9:31:00 PM (Pacific Daylight Time, UTC-07:00)
Once I added this code group below along with code group and permission set and assert commands Bryant mentioned I no longer got the System.Permissions.SecurtiyPermission message. Everything seems to work although everything is a little fuzzy as to why?
<br>
<br><CodeGroup
<br>class="UnionCodeGroup"
<br>version"1"
<br>PermissionSetName="FullTrust"
<br>Name="The name of your DLL. This shouldn't be necessary, but it worked for me."
<br>Description="">
<br><Imembershipcondition
<br>class="ZoneMembershipCondition"
<br>version="1"
<br>Zone="MyComputer"/>
<br></CodeGroup>
Don
Saturday, July 31, 2004 10:24:00 AM (Pacific Daylight Time, UTC-07:00)
This is just great Bryant! I was struggling with how to get started with this custom code. Good Job.
Anita
Monday, August 09, 2004 6:43:00 PM (Pacific Daylight Time, UTC-07:00)
Good Job! Will you please help me regarding the use of custom control in parameter in reporting services, tnx
GetBackers
Wednesday, August 11, 2004 4:14:00 AM (Pacific Daylight Time, UTC-07:00)
Excellent walk through. Thanks Bryant.
<br>Is it possible to pass a parameter to the report, and have the Assembly code adjust a column width based on the parameter value?
<br>
<br>Thanks
<br>
Tuesday, August 17, 2004 11:26:00 PM (Pacific Daylight Time, UTC-07:00)
how to use Dll's in reporting services
SS
Saturday, August 21, 2004 12:34:00 PM (Pacific Daylight Time, UTC-07:00)
I have been working on this for a few days and have hit every message board, called ms support and re-written the darn thing at least 20 times. I am still getting the #error in my report manager and have even added strong name. Is there a problem that's not being spoken of?
<br>
<br>
<br>JamesH.
Monday, August 23, 2004 11:48:00 AM (Pacific Daylight Time, UTC-07:00)
Hi,
<br>
<br>I'd appriciate if someone could point me to right direction.
<br>I've got my custom assembly working on development computer,
<br>but when I deploy it to production server I'm getting this error:
<br>
<br>Error while loading code module: ‘xxxxxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ab6b2957da4e38d6’. Details: ?
<br>
<br>I copied the assembly to Reporting Services /bin and copied permission set and code group settings to the config file.
<br>
<br>What am I missing?
<br>
<br>Thanks,
<br>Alex
<br>
Alex
Monday, August 23, 2004 12:03:00 PM (Pacific Daylight Time, UTC-07:00)
Alex,
<br>
<br>If you haven't checked yet, you should take a look at:
<br>
<br><a target="_new" href="http://www.microsoft.com/sql/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sqlserver.reportingsvcs">http://www.microsoft.com/sql/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sqlserver.reportingsvcs</a>
<br>
<br>There are really a lot of good links from MS on there albeit they're redundant. Good luck.
<br>
<br>JamesH
Tuesday, August 24, 2004 6:44:00 AM (Pacific Daylight Time, UTC-07:00)
Interestingly enough, it started working after I rebooted production server.
<br>
<br>Thanks,
<br>Alex
Alex
Wednesday, September 08, 2004 1:49:00 AM (Pacific Daylight Time, UTC-07:00)
Bryant,
<br>Thanks for all the info you posted. I'm working my way through, and I'm now working on the part were you are having us complete steps 3 & 4.
<br>
<br>I found something that I'm not sure about, syntactly.
<br>
<br>You code is as follows:
<br><FileIOPermissionAttribute(SecurityAction.Assert, Read="c:\temp\hello.txt")> _
<br>Public Shared Function HelloFromFile() as String
<br>
<br>I got an error stating READ is not defined. I did some reading on MSDN (<a target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAssert.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAssert.asp</a>)
<br>and saw the equals (=) sign is preceded with a colon, as such Read:="c...."
<br>
<br>Does this make a difference?
<br>
<br>rwiethorn
rwiethorn
Sunday, September 12, 2004 8:54:00 PM (Pacific Daylight Time, UTC-07:00)
Hi Bryant,
<br>
<br>Thanks for this wonderful article. Atleast the basic are clear now.
<br>
<br>I have a question here. With so many changes that are needed to be made to the config files, is there any way I can do it programatically ( just I can deploy reports using the rs.exe tool and scripts)?
<br>Because we cant expect the end user to make all these changes and (since xml is case sensitive), his whole application will go for a toss even if a small change is left out.
<br>
<br>Regards,
<br>
<br>Ravindra
Ravindra
Wednesday, September 22, 2004 9:30:00 PM (Pacific Daylight Time, UTC-07:00)
Excellent Job, Bryant
<br>Go Ahead
TYPXAH
Monday, September 27, 2004 6:10:00 AM (Pacific Daylight Time, UTC-07:00)
Thanks Bryant,
<br>Good work in clearing this up
Chris Russi
Monday, October 25, 2004 4:10:00 AM (Pacific Daylight Time, UTC-07:00)
I'm not sure what I am missing. I still get #error - where is the error more detailed than this? How would you ever know what the error is since documentation is so bad? I am trying to access SQL Server database.
<br>
<br>Here is my code:
<br>
<br> <System.Data.SqlClient.SqlClientPermission(Security.Permissions.SecurityAction.Assert, Unrestricted:=True)> _
<br> Public Shared Function GetMdx(ByVal sUserName As String) As String
<br> GetSqlConnection = New SqlClient.SqlConnection
<br> GetSqlConnection.ConnectionString = "Data Source=datasourcehere;User Id=userhere;Password=passwordhere"
<br> GetSqlConnection.Open()
<br> ' do query here
<br>
<br> End Function
<br>
<br>Here are entries in rssrvpolicy.config:
<br>
<br><PermissionSet
<br> class="NamedPermissionSet"
<br> version="1"
<br> Name="SqlClientPermissionSet"
<br> Description="A special permission set that grants access to do SQL Server DB Access.">
<br> <IPermission
<br> class="SqlClientPermission"
<br> version="1"
<br> Unrestricted="true"
<br> />
<br> <IPermission
<br> class="SecurityPermission"
<br> version="1"
<br> Flags="Execution, Assertion"
<br> />
<br></PermissionSet>
<br>
<br>
<br><CodeGroup
<br> class="UnionCodeGroup"
<br> version="1"
<br> PermissionSetName="SqlClientPermissionSet"
<br> Name="MyCustomAssemblyCodeGroup"
<br> Description="For my custom assembly">
<br> <IMembershipCondition
<br> class="UrlMembershipCondition"
<br> version="1"
<br> Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\MyDll.dll"
<br> />
<br></CodeGroup>
<br>
<br>
<br>Still get #error - not sure where to get any further detail.
Dan
Wednesday, October 27, 2004 7:45:00 AM (Pacific Daylight Time, UTC-07:00)
This article saved my life. I had serious deadline and knew that I had to use a custom code assembly to acheive the result. It pointed me in right direction and I was able to figure things out from there. The is honestly almost nothing else on the internet (believe me, I looked) that explains precisely how do it. Thanks Bryant!
Trevor
Monday, November 01, 2004 4:57:00 AM (Pacific Standard Time, UTC-08:00)
Your Article gave me a lot help. I write a custom code to connect to the database and get the right result in my report if I defined the connect string in my custom code directly. But I still struggle with my business objects vb files which using app.config value "Connectstring" to connect to the database which can be get by ConfigurationSettings.AppSettings("ConnectionString") in all business data access objects. I try use the ConfigurationSettings.AppSettings("ConnectionString") in my custom codes to test if I get right connect string but in report there is nothing display and no #error too. But if I use the web application or console application to test costum code in report. All get what I want. I reallize because the web application has the web.config file and console project has app.config they are all same as the business config's connection string. So I wonder if the report project in my solution should have some place to put the *.config file.
<br>
JJ
Tuesday, November 09, 2004 1:32:00 AM (Pacific Standard Time, UTC-08:00)
Bryant,
<br>Thanks for all the info you posted. I'm working with an assembly that read the Active Directory, in desing view all work nice!, but when i deploy my project, i recieve an error, my code is:
<br>
<br>Public Shared Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String
<br> Try
<br> Dim sPath As String = "LDAP://inet.com.sv" '' Dominio donde se buscara
<br> Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\")) ''' Usuario que se buscara
<br> Dim myDirectory As New DirectoryEntry(sPath, "Inet\lopez.carlos", "lc97028") 'pass the user account and password for your Enterprise admin.
<br> Dim mySearcher As New DirectorySearcher(myDirectory)
<br> Dim mySearchResultColl As SearchResultCollection
<br> Dim mySearchResult As SearchResult
<br> Dim myResultPropColl As ResultPropertyCollection
<br> Dim myResultPropValueColl As ResultPropertyValueCollection
<br> 'Build LDAP query
<br> mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount & "))")
<br> mySearchResultColl = mySearcher.FindAll()
<br> 'I expect only one user from search result
<br> Select Case mySearchResultColl.Count
<br> Case 0
<br> Return "Null"
<br> Exit Function
<br> Case Is > 1
<br> Return "Null"
<br> Exit Function
<br> End Select
<br> 'Get the search result from the collection
<br> mySearchResult = mySearchResultColl.Item(0)
<br> 'Get the Properites, they contain the usefull info
<br> myResultPropColl = mySearchResult.Properties
<br> 'displayname, mail
<br> 'Retrieve from the properties collection the display name and email of the user
<br> myResultPropValueColl = myResultPropColl.Item(inType)
<br> Return CStr(myResultPropValueColl.Item(0))
<br> Catch ex As System.Exception
<br> 'do some error return here.
<br> Return "Ha ocurrido el siguiente error: " + ex.Message
<br> End Try
<br> End Function
<br>
<br>I copied the assembly to Reporting Services /bin and copied permission set and code group settings to the config file.
<br>
<br>What am I missing?
<br>
<br>Thanks,
<br>Carlos
<br>
Carlos López
Sunday, December 12, 2004 12:54:00 PM (Pacific Standard Time, UTC-08:00)
Bryant,
<br>
<br>I am working on a report, which when opened in the browser should trap the user's window credentials and display his details alone. Impersonation is being for deploying the report on the report server. Therefore the user login info cannot be obtained from SQL server. Is there any alternative way of getting the user login credentials?
Haripriya V
Wednesday, December 22, 2004 3:55:00 AM (Pacific Standard Time, UTC-08:00)
Hi Bryant,
<br>
<br> Please forgive me, but im quite new to RS. This might sound kind of simple but ive yet to find how to tile records in a report. i have a need to generated a report which produces pics and associated values in a 2 x 2 or a 2 x 3 format which spill over onto new pages depending on the quantity. all the examples ive seen are straight forward matrices of data with details falling vertically down the table. id like to populate the report left to right and kick down to the next row once the first is filled (max value being at my discretion). any ideas?
<br>
<br>thanks ahead of time for all who help.
Jeremy K
Monday, December 27, 2004 10:54:00 AM (Pacific Standard Time, UTC-08:00)
how do i set the value of a textbox through custom code? (and can it be done if the textbox is situated in the header?
vijaya
Tuesday, December 28, 2004 4:33:00 AM (Pacific Standard Time, UTC-08:00)
Is it possible to use 3rd party controls/assemblies written for use in ASP.NET in Reporting Services? I would like to use the ChartFX for .NET in my reports, instead of the built-in charting functionality.
<br>
<br>TIA
Dane
Thursday, December 30, 2004 8:11:00 AM (Pacific Standard Time, UTC-08:00)
Would you happen to know how to add ActiveX controls onto/into custom SQL Reports? There are many articles that mention this as a possibility, but nothing that I have found will allow me to do so. Even a good link would be welcome.
<br>
<br>Thanks,
<br>Jim
Jim
Wednesday, January 12, 2005 6:33:00 PM (Pacific Standard Time, UTC-08:00)
Thanks Bryant.
<br>
<br>This example helpfull me to debug my report, because I didn't found in Microsoft documentation that the compiled dll must be copied in the "report designer" folder.
pierre
Wednesday, January 26, 2005 2:29:00 PM (Pacific Standard Time, UTC-08:00)
If anyone has done the same with database, could you please help me. I am really struggling.
Sunday, January 30, 2005 4:44:00 PM (Pacific Standard Time, UTC-08:00)
Hi Bryant,
<br>
<br>as with the others, fabulous work.
<br>
<br>Now to yet another question :)
<br>
<br>We are actually trying to call RS methods inside our custom assembly. For a simple example, I am just trying to list the reports. I figure if I can get this working I'll be happy. Question is what permissions do I need to set for the method and in the config file.
<br>
<br>any ideas
<br>
<br>Many thanks
<br>
<br>Matt
Tuesday, February 01, 2005 3:14:00 AM (Pacific Standard Time, UTC-08:00)
Here is a microsoft kb that also shows how to do this:
<br>
<br><a target="_new" href="http://support.microsoft.com/?kbid=842419">http://support.microsoft.com/?kbid=842419</a>
Frank Wisniewski
Monday, February 21, 2005 6:57:00 AM (Pacific Standard Time, UTC-08:00)
hello all,
<br>
<br>i went through this article and did everytihng that has to be done but when i try to connect to the report manager the report manager does not start up. It gives the following error Unable to communicate with the report server. Please verify the report server is operational. When i restore the rssrvpolicy.config the connection to the server is ok. Can anybody help out. This is really nerve racking.. and mdsn help is awful on this.. my rssrvpolicy.config looks like this
<br>
<br><Permissionset
<br>class = "NamedPermissionset"
<br>version="1"
<br>Name="CustomFunctionPermission"
<br>description="test"
<br><IPermission
<br>class = "OleDbPermission"
<br>version="1"
<br>Flags="Execution,Assertion"
<br>/>
<br></Permissionset>
<br>
<br><CodeGroup
<br>class="UnionCodeGroup"
<br>version="1"
<br>PermissionSetName="CustomFunctionPermission"
<br>Name="Test"
<br>Description="Description">
<br><IMembershipCondition
<br>class = "UrlMembershipcondition"
<br>version="1"
<br>Url="c:\Program Files\Microsoft SQL Server\80\Tools\Report Desinger0x;dll"/>
<br></CodeGroup>
<br>
<br>
<br>Trust Microsoft to bring up something that is difficult to work with always.
Ramachandran
Tuesday, February 22, 2005 5:22:00 AM (Pacific Standard Time, UTC-08:00)
Honestly have anybody tried this with a db connection. Whatever i do it always gives me the familiar #Error notification and nothign else. Is there any damn thing that must be done anymore also i dont know. I am running out of my wits can anybody help. If u need i can attach my policyfiles also. Please email to rveluthattil@yahoo.com
Ramachandran
Tuesday, February 22, 2005 6:26:00 AM (Pacific Standard Time, UTC-08:00)
This is the policy file that i am having. the sad part is without doing anything like this it works in the IDE perfectly but when i try to access it using the report manager then i get only #Error. Makes one feel that MS has taken pains to design something that will give only #Error.
<br>
<br><PermissonSet class="NamdPermissionSet"
<br>version="1"
<br>Name="Hopethisworks"
<br><IPermission class="SqlClientPermission"
<br>version="1"
<br>Unrestricted="true"/>
<br><IPermission class="SecurityPermission"
<br>version="1"
<br>Unrestricted="true"/>
<br></PermissionSet>
<br>
<br>
<br><CodeGroup class="UnionCodeGroup"
<br>version="1"
<br>PermissionnSetName="Hopethisworks"
<br>Name="Hopethisworkassemblylibrary"
<br><IMembershipCondition class="UrlMembershipCondition"
<br>version="1"
<br>Url="C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin\Hopethisworks.dll"/>
<br></CodeGroup>
<br>
Ramachandran
Friday, February 17, 2006 2:40:00 AM (Pacific Standard Time, UTC-08:00)
Great article Bryant...It has everything I wanted to know.
Dhruv
Tuesday, February 28, 2006 8:08:10 AM (Pacific Standard Time, UTC-08:00)
I kept on getting the same SecurityPermission error that everyone else is getting. I ended up going into the web.config and changing trust from "RosettaSrv" to "Full" and now I no longer get any error.
kevin
Thursday, April 06, 2006 9:23:49 AM (Pacific Daylight Time, UTC-07:00)
Hello,
I have successfully implemenetd a report whcih uses Custom Assembly. The problem is when I have a subcription for this report, it fails with the error that
"Failed to load expression host assembly. Details: File or assembly name VaryRSStyleSheet, or one of its dependencies, was not found." where VaryRSStyleSheet is my assembly.

Any help would be highly appreciated.
Thanks
Adi
Adi
Friday, May 05, 2006 3:43:47 AM (Pacific Daylight Time, UTC-07:00)
Hi
Thanks for this nice information!:)

Could you please tell me if its possible to display a Message box or Alert in RS with custom code? Basically, i want to compare the value of two parameter and based on certain condition i want to display an Alert. e.g. There are two param of a reports; "Start Date" and "End Date". Is it possible to check the date before excuting the reports. I want to check that "Start date" must less than equal to "End Date". How can i do this reqporting server.
Tuesday, October 24, 2006 5:48:22 AM (Pacific Daylight Time, UTC-07:00)
Hi friend, great article!
Could you help me to find a solution to my problem?
I want to create just one report and one DataSet, but I need to change the DataSource and/or the Server on DataSet.
How can I do it with Custom Code? Could I replace some DataSet properties by report parameters?

Regards!
Lucas Almeida
Tuesday, November 21, 2006 8:59:47 PM (Pacific Standard Time, UTC-08:00)
Thanks, I got a Good stuff from this article.
Thanks a lot
Mallesh
Thursday, November 23, 2006 8:55:41 PM (Pacific Standard Time, UTC-08:00)
Hi,
I have a problem in impleteing a concept in Sql Reports 2000. The problem is :
I have 4 columns in the report and is in a Group. The feilds are Credit amt,Debit amt and balance amt.
In the group I will be getting number of rows.

The calculation part should be
Balance = Balance + ( credit - debit)
ie, In the first row I will be getting the calculation and comming to the second row the first row balance should be added second row and so on till the group is complete.
How to do this issue.
Can any one give me a solution ?
Mallesh
Thursday, December 07, 2006 2:20:14 AM (Pacific Standard Time, UTC-08:00)
Bryant,

Found your article on google. Having gone through all the MSDN articles on custom assemblies (the same ones you mentioned), my assembly still wasn't working. Your article had actual example code of the Hello World style, the type of super-simple code that doesn't make things too complicated. It was there that I found I was missing a few things.

Thanks! Maybe I'll make that deadline now... ;-)
Remy Marx
Sunday, December 10, 2006 11:06:54 PM (Pacific Standard Time, UTC-08:00)
I am trying to work my way through through the Custom Assemblies section, but I can't get past this error when I try to preview the report:
Error while loading code module: ‘MyCustomAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Details: Could not load file or assembly 'MyCustomAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

I have done everything that this article says, plus I have also followed the steps found in "How to grant permissions to a custom assembly that is referenced in a report in Reporting Services" by Microsoft, but I continue to get the error.

Any suggestions?

Thanks,
Amy Bolden
Sunday, January 07, 2007 11:29:26 PM (Pacific Standard Time, UTC-08:00)
How i use textbox.value in code?
Roman
Tuesday, February 06, 2007 9:26:10 PM (Pacific Standard Time, UTC-08:00)
Is it Possible to merge a two column in Matrix data region?
Flexi
Friday, February 16, 2007 3:57:32 AM (Pacific Standard Time, UTC-08:00)
Bryant,

one of the earlier posts here posed the question of how to create custom aggregators. I've been googling all over the place but have not found a way to do it. providing a sum() function but not a concat() function seems to me an eggregious omission on the part of Microsoft... certainly others out there must be feeling my pain.

have you any ideas on how to accomplish this?

1,000 thanks - erick

p.s. would you mind e-mailing me? e AT arix.com

here's the other poster's question:

> Within a group you have a column of string
> values-Say states for example on a group summary
> line you want a concatenation of the string state
> values for all rows in the group.
> so you might have
> ID State
> 1 AZ
> 1 AL
> 1 MO
>
> Summary group footer:
> 1 AZ, AL, MO
>
> This is a little similar to the "running total"
> idea but instead of adding values I want to
> concatenate strings togather.

ekkis
Thursday, March 01, 2007 12:56:41 AM (Pacific Standard Time, UTC-08:00)
I have been asked to create a data entry form and make it available from Reporting Services. Yes, the request seems rediculous to me too, but I haven't talked them out of it yet.

Has anyone done something similar? If so, do you have some code to get me started?
Will
Sunday, March 11, 2007 7:56:09 PM (Pacific Standard Time, UTC-08:00)
i find the article quite usefull, but i have some query regarding writting custom code. my problem is to change the value of textboxes at run time. if i have "Unit of Measurement" as textbox value it should be displayed as "UOM". and i am working on server side reports. Pls help me how can i change the value of textboxes. how is iterate on textboxex in a server side report. hope you understand my problem.
zeeshan
Wednesday, March 21, 2007 11:44:04 PM (Pacific Standard Time, UTC-08:00)
To everyone trying to access an SQL source instead of just a text file try this link:

http://support.microsoft.com/?kbid=842419

At point 1.l (that's L), add in the SQL Client permissions with grant all aswell.

The .NET config tool will generate the xml code for you but you have to cut & paste it to the RS config. I think it may matter that you put it in exactly the right place. For me the permissions it generated was put at the end of the permission sets and the codegroup was just after the first code group.

Hope this helps,
John
John Leonard
Thursday, May 03, 2007 11:01:07 AM (Pacific Daylight Time, UTC-07:00)
Bryant,

Thanks for your great article.

I have this problem addressing a Global reference(?) in my embedded code:

PUBLIC FUNCTION myUserID() AS String
DIM LastSeparator
LastSeparator = User!UserID.LastIndexOf("\")
RETURN User!UserID.Substring(LastSeparator+1)
END FUNCTION

When I tied a TextBox to it as: =Code.myUserID(),
I got this error:

There is an error on line 2 [BC30469] Reference to a non shared member requires an object reference.

What do I need to do?

Thanks.
dkhuon
Wednesday, May 16, 2007 5:54:03 AM (Pacific Daylight Time, UTC-07:00)
Hi Bryant:

I enjoyed your article on Writing Custom Code - I felt the same way about there not being enough information about it and I'm still trying to muddle through it and fix errors. I think I followed everyhing correctly but I keep getting the error: "The Value expression for the Textbox15 contains an error. [BC30469] Reference to a non-shared member requires an object reference." I have written a custom assembly that basically calculates a percentage and handles dividing by zero since IIf statements cannot handle divide by zero operations. The code is:
namespace Calculations
{
public class calcPercentage
{
public decimal Percentage(decimal decValueOne, decimal decValueTwo)
{
decimal decPercentage = 0;

if (decValueOne == 0 || decValueTwo == 0)
{
decPercentage = 0;
}
else
{
decPercentage = (decValueOne - decValueTwo) / decValueOne;
}
return decPercentage;
}

}
}

In my textbox, I put =Calculations.calcPercentage.Percentage(SUM(Fields!PreviousYTDExpenseAmount.Value, "Template_OutputData_Sales"), SUM(Fields!PreviousYTDExpenseAmount.Value, "Template_OutputData_CGS"))

Could you provide any insight as to what my problem might be? I have been looking at this so long I could possible be overlooking something simple. Any help would be greatly appreciated. Let me know if you need any additinal information.

Thank you!
Tianna
Tuesday, May 29, 2007 7:26:53 PM (Pacific Daylight Time, UTC-07:00)
dkhuon, you can get around this by passing User!UserID as a parameter into your function. then your custom code can use its local parameter. Something like this

PUBLIC FUNCTION myUserID(UserID as String) AS String

DIM LastSeparator

LastSeparator = UserID.LastIndexOf("\")

RETURN UserID.Substring(LastSeparator+1)

END FUNCTION


=Code.myUserID(User!UserID)

Alex
Tuesday, May 29, 2007 9:35:53 PM (Pacific Daylight Time, UTC-07:00)
Hi,
Has anyone solved this problem? It is copy from previous post.

Assume data in Groups
Within a group you have a column of string values-Say states for example
on a group summary line you want a concatenation of the string state values for all rows in the group.
so you might have
ID State
1 AZ
1 AL
1 MO

Summary group footer:
1 AZ, AL, MO

This is a little similar to the "running total" idea but instead of adding values I want to concatenate strings togather.

Any suggestions.
Please email me at franta1346 at yahoo.com
Thanks
Frank
Tuesday, June 05, 2007 12:23:24 AM (Pacific Daylight Time, UTC-07:00)
Hi,

I am using custom assembly in reporting services. on development everything is working fine. When i try to upload .rdl files on a separate / different / production machine to check its working it is giving following error
Error while loading code module: ‘reportHelperLib, Version=1.0.2705.22780, Culture=neutral, PublicKeyToken=null’. Details: ? (rsErrorLoadingCodeModule) Get Online HelpError in class instance declaration for class reportHelperLib.rptHelpers: [BC30002] Type 'reportHelperLib.rptHelpers' is not defined. (rsCompilerErrorInClassInstanceDeclaration)

i have gone through many articles but could not solve this problem. i try to add reportHelperLib.dll in gac but invain. i copied reportHelperLib.dll in C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin but still its not working. i have restarted my machine as well but :(

can anyone please tell me what i am missing?

Regards

Ali
Ali
Friday, September 14, 2007 6:48:34 AM (Pacific Daylight Time, UTC-07:00)
I am quite desperate with my custom assembly dll (not in reporting services). After 2 weeks I still do not get it running on my server. On an old server I could, but now it doesnt. If you think you could help me out I can give you a remote rdp login. Please contact me at: www.voice4all.com and then contact tab. Thank you,
J.
J O
Sunday, September 16, 2007 5:03:34 PM (Pacific Daylight Time, UTC-07:00)
hi

i have written custom function in code part in that function we are passing parameter

for ex : code.Get(Parameters!param.Value)

above function iam calling in datasource expression for generating connection string while previw i can connect multiple database and view report, after deploying it displays error ...

i hope parameter is not passing to that function

plz help me in this issue
ganesh
Sunday, October 07, 2007 11:17:42 PM (Pacific Daylight Time, UTC-07:00)
Hello Friends,

I have one requirement regarding embedding the HTMl content in sql reporting service, i have a FCK editor value in db, i want to show the values in this report with the specified format in FCK editor.

Thanks.
Shankar
Tuesday, October 16, 2007 8:48:27 PM (Pacific Daylight Time, UTC-07:00)
bryantlikes said:
how do i set the value of a textbox through custom code? (and can it be done if the textbox is situated in the header?

I have the same question, how can i access report items in custom code, is that possible or not
Thursday, October 18, 2007 2:44:45 AM (Pacific Daylight Time, UTC-07:00)
these static fields are a bad idea because of two people are running the report at the same time their data will be shared.
Matt
Thursday, November 15, 2007 12:04:16 PM (Pacific Standard Time, UTC-08:00)
I've followed all of these steps, but I keep getting the following message when trying to preview or run in debug:

The Value expression for the textbox ‘textbox1’ contains an error: [BC30456] 'GetDate' is not a member of 'ALMRSFunctions'

However, 'GetDate' is a valid static member of 'ALMRSFunctions'. Also, when I add the namespace in front of the class name, it says it's not defined.

Any suggestions?
John F
Thursday, December 06, 2007 5:01:25 AM (Pacific Standard Time, UTC-08:00)
I have a question that I believe was asked already, but I don't see a response. I'm trying to do a calculation where I need to subtract a value in the current row from a value for the same field in the next row. There is a Previos function to get a value from the previous row, but I have not been able to find a way to get the value from the next row. Any help would be appreciated. Email: tmeemken@idsgrp.com
Terry
Wednesday, December 26, 2007 4:58:04 AM (Pacific Standard Time, UTC-08:00)
Hello,
Ì'm working with SQLServer2005 y want setup my printer, setup the PaperSize and the Orientation.

Who I go.!!?

Thaks for you help to all.
Luis
Luis Herrera
Wednesday, December 26, 2007 5:36:19 AM (Pacific Standard Time, UTC-08:00)
Please, send me you answer to todoherrera@gmail.com
Thanks friends.

Luis
Luis Herrera
Wednesday, January 23, 2008 4:39:03 AM (Pacific Standard Time, UTC-08:00)
Amy

Re: Error while loading code module: ‘MyCustomAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’

I also had this error and found that I needed to put the MyCustomAssumbly.dll into the the %PROGRAMFILES%\Visual Studio 8\Common7\IDE\PublicAssemblies and then create a reference to it.

Thanks Bryant for taking the time to create an excellent blog!

David
Thursday, April 03, 2008 11:40:33 PM (Pacific Standard Time, UTC-08:00)
I am new to SSRS and not sure how to capture a dataset returned from a .Net assembly. My requirement is that my .net assembly will be returning a dataset with 2 columns and it would be containing lot of rows. Not sure how to capture these columns in my SSRS reports. My deadline is approcahing and really need your help. I would appreciate if you could reply me on aanchal_1@rediffmail.com.
Aanchal
Thursday, April 17, 2008 2:44:01 AM (Pacific Daylight Time, UTC-07:00)
Cajn I have print code in the Custome Assembly to change the the print orienattion of the report pages?
Ashish
Thursday, June 12, 2008 12:48:41 AM (Pacific Daylight Time, UTC-07:00)
Hi,
Great article but only preview works.
when i tried to run it on server it shows #error#.
I want to mention that i did all the steps you wrote.
Are you sure that it worked for you?(on server not priview) , it is preety argent!!!
Thanks
boaz
Tuesday, July 15, 2008 7:27:04 PM (Pacific Daylight Time, UTC-07:00)
Hi,
i want to make my report multilingual.for that i need change static
label(like table header,textbox text) used in report according to the current
culture,which i am trying to do using custom assembly.
But it is not running in IE,giving #Error but working well in Report Designer.
Here is my class code:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Collections;
using System.Resources;
using System.IO;
using System.Threading;

namespace RptClassLibrary
{
public class Class1
{
public static string test()
{
return "hello";
}

public static string GetMessageDetails(string messageCode,string userCulture)
{
string errorMessage = string.Empty;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(userCulture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(userCulture);

ResourceManager resourceManager =
new ResourceManager("RptClassLibrary.Resource", Assembly.GetExecutingAssembly());

errorMessage = resourceManager.GetString("DefaultLink");
return errorMessage;
}
}
}
==========
and here is my rssrvpolicy.config file
=========
<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition" Description="System.Security.Policy.AllMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission" Description="System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="DnsPermission" Description="System.Net.DnsPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="EnvironmentPermission" Description="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FileIOPermission" Description="System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup" Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="IsolatedStorageFilePermission" Description="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet" Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="PrintingPermission" Description="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="RegistryPermission" Description="System.Security.Permissions.RegistryPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SecurityPermission" Description="System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SocketPermission" Description="System.Net.SocketPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition" Description="System.Security.Policy.StrongNameMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup" Description="System.Security.Policy.UnionCodeGroup, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition" Description="System.Security.Policy.UrlMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPermission" Description="System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="ZoneMembershipCondition" Description="System.Security.Policy.ZoneMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Execution">
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution"
/>
</PermissionSet>

</NamedPermissionSets>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="AllMembershipCondition"
version="1"
/>

<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="Execution"
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"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100512C8E872E28569E733BCB123794DAB55111A0570B3B3D4DE3794153DEA5EFB7C3FEA9F2D8236CFF320C4FD0EAD5F677880BF6C181F296C751C5F6E65B04D3834C02F792FEE0FE452915D44AFE74A0C27E0D8E4B8D04EC52A8E281E01FF47E7D694E6C7275A09AFCBFD8CC82705A06B20FD6EF61EBBA6873E29C8C0F2CAEDDA2"
/>
</CodeGroup>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Execution"
Description="This code group grants MyComputer code Execution permission. ">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code signed with the Microsoft strong name full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code signed with the ECMA strong name full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="00000000000000000400000000000000"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Report_Server_Strong_Name"
Description="This code group grants Report Server code full trust. ">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100272736AD6E5F9586BAC2D531EABC3ACC666C2F8EC879FA94F8F7B0327D2FF2ED523448F83C3D5C5DD2DFC7BC99C5286B2C125117BF5CBE242B9D41750732B2BDFFE649C6EFB8E5526D526FDD130095ECDB7BF210809C6CDAD8824FAA9AC0310AC3CBA2AA0523567B2DFA7FE250B30FACBD62D4EC99B94AC47C7D3B28F1F6E4C8"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>
</CodeGroup>
<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>
<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust"
Name="RptClassLibrary" Description="This code group grants FullTrust to
AAC.RSLocalize2007.dll.">
<IMembershipCondition class="UrlMembershipCondition" version="1"
Url="E:\ReportClass\RptClassLibrary\RptClassLibrary\bin\Debug\RptClassLibrary.dll" />

</CodeGroup>

</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>

======
i add only the last codegroup.
But things is not working,plesae help me.
Dibakar
Dibakar
Monday, September 22, 2008 5:48:04 AM (Pacific Daylight Time, UTC-07:00)
I'm trying instantiate a C# object into a report (Reporting Services 2005) but it's don't work!

Using static methods.. Ok. (My class is ok ;) )

In report properties I set class name and instance name and in field's expresion: =instanceName.method()

:(

Some tips?

Thanks

ozlistas@gmail.com
Thursday, October 02, 2008 8:56:50 AM (Pacific Daylight Time, UTC-07:00)
I am trying to create a grand total of a filtered group. usual methods produce a grand total of the entire dataset not the filtered group records. I am using your example of embedded code to do this but it seems to fail or reset to 0 outside the filtered group. the code is:

Public Amt1 as double = 0
Public Function SayHello (amt as double) as double
Amt1 = Amt1 + amt
Return Amt1
End Function

Am I doing something wrong or is this not able to accomplish the task?
Perry
Monday, January 19, 2009 12:03:52 AM (Pacific Standard Time, UTC-08:00)
very helpful tutorial: thanks bryant
andrea
Tuesday, May 19, 2009 9:01:48 PM (Pacific Daylight Time, UTC-07:00)
I had a reference library added into the custom assembly. I've asserted the permissions required for a number of methods used in the code. When running the report in preview mode it is fine but running it in debuglocal mode it returns an error due to a PSLibrary.PSContextInfo.SerializeToString(contextinfo) function as follows:
Message: Request failed.
Exception Type: 0cham2yl
Source: System.Security.SecurityException
StrackTrace:
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPSContextInfo.Write2_PSContextInfo(String n, String ns, PSContextInfo o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPSContextInfo.Write3_psci(Object o)
TargetSite: Void Write2_PSContextInfo(System.String, System.String, Microsoft.Office.Project.Server.Library.PSContextInfo, Boolean, Boolean).

Any idea how I could resolve this?
KH
Thursday, June 11, 2009 9:16:15 PM (Pacific Daylight Time, UTC-07:00)
Hi...
I would like to open if we ca open a connection
to an oracle database and extract data from there,
manipulate them and add them to my report by writing custom codes
Yogesh
Wednesday, June 24, 2009 1:59:07 PM (Pacific Daylight Time, UTC-07:00)
Hi,

I am trying to get the DnsName of the PC which is used for viewing the reports and for that I am referencing the .NET DLL System.Net.dll. I have written appropriate code in the Code section under Report Properties. Referenced the dll using the reference tab. But while trying to view the report I am getting below error. Can someone please help me out with this

Error: Request for permission of type ‘System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, Public KeyToken= b77a5c561934e089’ failed.

Thanks.

Deepankar Neogi, Staff. Software Engineer
Eclipsys Corporation
Deepankar Neogi
Tuesday, August 25, 2009 7:40:07 PM (Pacific Daylight Time, UTC-07:00)
Hi guys i was wondering once i have the custome code in, and i try to go to my expression and call the function I type "Code." then when the intellisense comes up it doesnt show the function name, is there a specific reason for this?
Stripes
Thursday, October 01, 2009 10:45:16 PM (Pacific Daylight Time, UTC-07:00)
Hi Brian,
1. I have a report that all parameters have a default so
the report runs when it is opened before you click View Report.
2. I don't want the report to run because it is pulling way too much data. I want the user to fill in one of the five parameters to limit the data (I don't care which one).
3. I wrote custom code that checks to see if all parameters are nothing and returns a boolean.
4. I use the Hidden property, with an expression that calls the custom code to either show a textbox saying "Please fill in one parameter" or the table that is the actual report.
5. The problem is, that even when my table (actual report) is hidden because they did not enter a parameter, the dataset is still running.
6. How can I get the dataset to NOT run unless they have entered one of the parameters. I have tried several things in my custom code but have not been successfull.

Thanks, Linda
Linda
Comments are closed.