Centralising Reporting Services Stylesheets

  • Hi, Thank for this article. It was very helpful for understanding adding assemblies to reporting services.

    However, I have run into a problem. Everything worked like charm, in a report, I changed background-color of to the value I got from the the assembly created..etc until I tried to connect to a database and get the value from there. And the reporting services just displays #Error

    The function that's connect to database is working fine. The reason is b/c I created Windows App that calls this function actually receives value from DB by calling this function.

    The problem happens only when I call this from Reporting Services report.

    I'm thinking it's some kind of security issue?

    I hard-coded connection string to db in the function. basically, I used the exact same code as you posted in this article. I just changed values of connection string.

    I appreciate any help or any response.

  • Hi chikako wakishima,

    have you done the things I told , add the SQLClientpermission and codegroup. You have to do all of these to get the assambly running on RS.

    Regards

  • For those of you struggling, I was excited about Adam's solution, but then I ended up going with an alternate approach found here (http://www.simple-talk.com/sql/reporting-services/reporting-services-with-style/[/url])

    mainly because it looked simpler from an "I don't know what I'm doing" standpoint.:-D

    Seems to work well also.

    ---------------------------------------------------------
    How best to post your question[/url]
    How to post performance problems[/url]
    Tally Table:What it is and how it replaces a loop[/url]

    "stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."

  • Does anyone know of a good way to avoid hard-coding the database connection string?

    MyConnection = New SqlConnection("server=localhost;uid=USERNAME;pwd=PASSWORD;database=RSStyles")

    It would be preferable to make use of an existing shared database connection, or have this database connection information stored in a config file, since it could well be the case that the connection string is different in dev and production.

  • A blog post I just wrote about how to set up the DLL to use an external XML file:

    http://thinkdevcode.blogspot.com/

    It goes over all of the security settings you need to get it to work. Comment on it if you have any problems/questions.

  • Is anyone experiencing slow export to excel performance using this? Exporting to csv is very fast, but it can take minutes to export to excel.

  • Thanks a lot for tis code. I pretty much used as is, apart from one issue - This was the fact that the the database was hit too many times. for example for a matrix of substantial cells the database will be hit everytime a cell needs to be formatted.

    To overcome that I used a a shared list of reportStyles that could be used between instances of the datadrivenstyle library. See below (following 2 lines are key - Private Shared reportStyles As List(Of ReportStyle) & If reportStyles Is Nothing Then):

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System.Security

    Public Class DataDrivenStyleLibrary

    'Declare shared item that can be shared between instances

    Private Shared reportStyles As List(Of ReportStyle)

    Public Shared Function dbStyle(ByVal ReportSection As String, ByVal StyleType As String) As String

    Dim sStyle As String

    sStyle = ""

    'Check to see if reportstyles list exists already created and if it does not then create it

    If reportStyles Is Nothing Then

    reportStyles = New List(Of ReportStyle)

    ' Set up the command and connection objects

    Dim MyConnection As SqlConnection

    MyConnection = New SqlConnection("Data Source=IMGSERVER17; Initial Catalog=ReportServer; Integrated Security=SSPI;")

    Dim cmd As New SqlCommand

    cmd.Connection = MyConnection

    cmd.Connection.Open()

    cmd.CommandType = CommandType.StoredProcedure

    cmd.CommandText = "pr_GetStyle"

    ' Read the data, and populate report style list

    Dim ddlValues As SqlDataReader

    ddlValues = cmd.ExecuteReader()

    While ddlValues.Read

    Dim rStyle = New ReportStyle()

    rStyle.ReportSection = ddlValues.GetString(0)

    rStyle.StyleType = ddlValues.GetString(1)

    rStyle.StyleDefinition = ddlValues.GetString(2)

    reportStyles.Add(rStyle)

    End While

    'Close any open connections

    cmd.Connection.Close()

    ' return the selected value to the calling proceure

    End If

    'Loop up particular style from object

    For Each rs In reportStyles

    If rs.ReportSection = ReportSection And rs.StyleType = StyleType Then

    sStyle = rs.StyleDefinition

    Exit For

    End If

    Next

    Return sStyle

    End Function

    End Class

    Friend Class ReportStyle

    Private sType As String

    Private rSection As String

    Private sDefinition As String

    Public Property StyleType() As String

    Get

    Return sType

    End Get

    Set(ByVal value As String)

    sType = value

    End Set

    End Property

    Public Property ReportSection() As String

    Get

    Return rSection

    End Get

    Set(ByVal value As String)

    rSection = value

    End Set

    End Property

    Public Property StyleDefinition() As String

    Get

    Return sDefinition

    End Get

    Set(ByVal value As String)

    sDefinition = value

    End Set

    End Property

    End Class

  • Very nice! Thank you for suggesting this. It resolves the core weakness of the technique.

    Regards,

    Adam

  • Hi,

    I've been trying to get this to work for days but I keep getting the permissions error that you all talked about. I've added all the suggested code (modified the rssrvpolicy.config file, updated the DynamicStyleLibrary and gave it "Full Trust"). Nothing works. Still get this error:

    Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Can anyone help?

    Thanks,

    Beth

    P.S.

    I am NOT a developer. I know nothing about assemblies, but have had a developer look at this with me...we're both stumped.

  • Unfortunately, I am encountering the same problem...

    It seems my namespace is not declared, despite setting up the Assembly Reference as instructed.

  • Hello!

    Is there a way to add a link to another site on the main page of the reporting services or modify Help link? We have quite a few reports and will be time consuming to modify each of them.

    Thanks in advance!!!!

Viewing 11 posts - 61 through 70 (of 70 total)

You must be logged in to reply to this topic. Login to reply