Reporting Services and custom Library

By | March 29, 2010

In Reporting Services you can’t create multilanguage Reports. You have to load the language resources from a DB, File etc.
Last week I wrote a DLL, which reads language resources from a database. The DLL worked well… (in my test Console Application).
Afterwards, I added the DLL to my Report and tried to load a text from the database. But I got an security permission exception, because, you can’t access from a custom Library external resource like files or databases. (In the preview mode the message “#Error” appears.)

Solution:
First you have to write following code in your library.

SqlClientPermission perm = new SqlClientPermission(PermissionState.Unrestricted);
perm.Assert();
// Database connection and query
CodeAccessPermission.RevertAssert();

Compile the library and deploy the file to the Report Server. You have to put the dll in the Bin folder of the Report Server.
Afterwars, you must define a CodeGroup in the rssrvpolicy.config file. (Placed inside the Report Server folder.)


  
 

This CodeGroup must be placed under the last CodeGroup. But it must be placed in the same parent element.
Save the file.

In the Reporting Services project add a reference to the new library (from the Report Server Bin folder!!!).
Deploy the report and try to open. The database text should appear now.

You have to make the same procedure if you want to have the database resources in Visual Studio / Business Intelligence Studio.
The CodeGroup must be placed in the rspreviewpolicy.config and the dll must be added in the PrivateAssemblies (Visual Studio) folder.