I am trying to create a custom SSRS assembly that formats the style of a report based on the value of an SQL table.
I need to be able to preview this locally and deploy to the reporting server.
This would allow me to roll out style changes to a series of Paginated Reports from a central place.
Example expression: =ProjectName.ClassName.getItemStyle("Header", "Font-Family")
The expression parses the values I'm looking for then goes off and returns a value from the SQL table, in this case "Verdana".
I've been through various steps to get this working as far as I have and have now reached a permissions problem. The assembly works fine so long as I don't try to connect to an SQL server.
In which case I receive this error:
The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I have tried adding in assembly permissions and editing the rssrvpolicy config file to no avail, but I feel like I am missing something and I'm not too sure I understand the Microsoft documentation on this.
I have also signed the assembly and installed the certificate.
Code I've used:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Security;
[assembly: AllowPartiallyTrustedCallers]
namespace CC_rpt
{
public class lib
{
public static string getItemStyle(string parse)
{
string val;
val = "1";
try
{
using (SqlConnection oConn = new SqlConnection("Data Source=DBServer;Initial Catalog=DBName;Integrated Security=SSPI"))
{
var oCmd = new System.Data.SqlClient.SqlCommand();
oCmd.Connection = oConn;
oCmd.CommandText = "select singleValue FROM Table WHERE Column = @Param";
oCmd.Parameters.AddWithValue("@Param", parse);
val = oCmd.ExecuteScalar().ToString();
}
}
catch (System.Data.SqlClient.SqlException e)
{
val = e.ToString();
}
return val;
}
}
}
OS: Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1)
Visual Studio: Microsoft Visual Studio Professional 2017 Version 15.9.13
Server SSRS Reporting Services 2016
Installed Products:
SQL Server Reporting Services 15.0.1528.0 SQL Server Integration Services 15.0.1300.371
.Net libraries I'm primarily trying to use: System.Data.SqlClient
targeting .Net Framework: 4.6.1
Paths I'm copying the DLL to (Via a post build event)*:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\MSBuild C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PrivateAssemblies C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Reporting Services C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\SSRS C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin
Assembly security settings: I have signed the assembly created the string key file (pfx) and installed it.