Showing posts with label systemdata. Show all posts
Showing posts with label systemdata. Show all posts

Monday, February 13, 2012

'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral,

I have a report that uses some embedded custom code. The embedded custom code is a function that execute some sql query on a sql server database.Everything works fine in Visual studio. The report gets deployed on the server successfully, however when running the report from report manager i get the following error message :

  • The Hidden expression for the table ‘table1’ contains an error: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
  • Here is the code :

    ************************************************************************

    Public function get_field() as string
    Dim myConnection As System.Data.SqlClient.SqlConnection
    Dim myCommand As System.Data.SqlClient.SqlCommand
    Dim data_reader As System.Data.SqlClient.SqlDataReader
    Dim field(100) as string
    Dim i as integer
    Dim j as integer
    Dim sql_field as string
    Dim nbr_field as integer
    Dim rtn_string as string


    i = 0
    sql_field ="Select field from mytable"
    myConnection = New System.Data.SqlClient.SqlConnection("Datasource=xxx.xxx.xxx.xx\mydatabase;Initial Catalog=mydatabase;User Id=user1;Password=password1;")
    myConnection.Open()
    myCommand = New System.Data.SqlClient.SqlCommand(sql_field, myConnection)
    data_reader = myCommand.ExecuteReader()
    While data_reader.Read()
    if data_reader.HasRows then
    field(i)= data_reader(0).ToString()
    end if
    nbr_field = nbr_field + 1
    i= i+1
    End While
    data_reader.Close()
    myConnection.Close()


    for j = 0 to nbr_field -1
    rtn_string = rtn_string + field(j) + ","
    Next j

    rtn_string = left(rtn_string,rtn_string.length-1)
    return rtn_string
    'return sql_cmd
    'return yes_no
    'return lkupfield
    end function

    ******************************************************************

    Why do i get the error message ?, is this related to Code Access Security issues with .net framework. if yes

    how do i set the Security so the report server or report manager allows embedded custom code to be executed. Any advice ?

    Chi


    To set code access security for your custom code, see the following article: http://msdn2.microsoft.com/en-us/library/aa237680(SQL.80).aspx

    -Albert

    |||

    Thanks Albert, i have one more question, do i have to grant permission even if the code that i use is embedded in the report .I mean i did not create a custom DLL. In other words do i have to grant permission to the code even if it's embedded in the report, but in my code i reference System.Data.SqlClient.

    Public function get_field() as string
    Dim myConnection As System.Data.SqlClient.SqlConnection
    Dim myCommand As System.Data.SqlClient.SqlCommand
    Dim data_reader As System.Data.SqlClient.SqlDataReader
    Dim field(100) as string
    Dim i as integer
    Dim j as integer
    Dim sql_field as string
    Dim nbr_field as integer
    Dim rtn_string as string


    i = 0
    sql_field ="Select field from mytable"
    myConnection = New System.Data.SqlClient.SqlConnection("Datasource=xxx.xxx.xxx.xx\mydatabase;Initial Catalog=mydatabase;User Id=user1;Password=password1;")
    myConnection.Open()
    myCommand = New System.Data.SqlClient.SqlCommand(sql_field, myConnection)
    data_reader = myCommand.ExecuteReader()
    While data_reader.Read()
    if data_reader.HasRows then
    field(i)= data_reader(0).ToString()
    end if
    nbr_field = nbr_field + 1
    i= i+1
    End While
    data_reader.Close()
    myConnection.Close()


    for j = 0 to nbr_field -1
    rtn_string = rtn_string + field(j) + ","
    Next j

    rtn_string = left(rtn_string,rtn_string.length-1)
    return rtn_string
    'return sql_cmd
    'return yes_no
    'return lkupfield
    end function

    chi

    |||

    Sorry, I didn't read your post carefully enough. Yes, you need to set code access security for the custom code in your report. The instructions are in the following article: http://msdn2.microsoft.com/en-us/library/aa237693(SQL.80).aspx. You need to modify the permissions for the "Report_Expressions_Default_Permissions" code group in the policy file.

    -Albert

  • Saturday, February 11, 2012

    #error when referencing System.Data and Microsoft.AnalysisServices.AdomdClient

    Hi,

    I created a function in the Report Properties -> Code Section that uses System.Data and Microsoft.AnalysisServices.AdomdClient.

    In the reference section I have made references to these Assemblies. When I preview my report on the preview tab, everything works fine. But when I deploy it to the server I get #error in the text box which calls the function.

    Any ideas?

    Thanks in advance.

    You may want to carefully read this related thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=460220&SiteID=1

    Basically, it is not working in the report server environment due to missing code access security permissions. I believe teh AdomdClient requires FullTrust permissions.

    -- Robert

    |||

    Thanks. The "Expression host assembly" only had execution persmissions. I created a custom assembly and granted it FullTrust.

    Thanks again for pointing me in the right direction.

    |||

    Hi there. When I created my custom assembly, the only way that I was able to get it to work was to use an OLE db connection instead of the Adomdconnection. I had followed these steps here:

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

    The reason was that I didn't know what type of permission to assert in my code for an Adomdconnection since there wasn't an 'AdomdConnectionPermission' object. Has anyone got this to work with an Adomdconnection object?

    My second question is that when my report executes the functions in the assembly, they execute with the credentials of the server identity. Is there a setting in any config file that I can change so that the assembly can impersonate the current user and execute the functions with the user's credentials?

    Thanks.

    #error when referencing System.Data and Microsoft.AnalysisServices.AdomdClient

    Hi,

    I created a function in the Report Properties -> Code Section that uses System.Data and Microsoft.AnalysisServices.AdomdClient.

    In the reference section I have made references to these Assemblies. When I preview my report on the preview tab, everything works fine. But when I deploy it to the server I get #error in the text box which calls the function.

    Any ideas?

    Thanks in advance.

    You may want to carefully read this related thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=460220&SiteID=1

    Basically, it is not working in the report server environment due to missing code access security permissions. I believe teh AdomdClient requires FullTrust permissions.

    -- Robert

    |||

    Thanks. The "Expression host assembly" only had execution persmissions. I created a custom assembly and granted it FullTrust.

    Thanks again for pointing me in the right direction.

    |||

    Hi there. When I created my custom assembly, the only way that I was able to get it to work was to use an OLE db connection instead of the Adomdconnection. I had followed these steps here:

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

    The reason was that I didn't know what type of permission to assert in my code for an Adomdconnection since there wasn't an 'AdomdConnectionPermission' object. Has anyone got this to work with an Adomdconnection object?

    My second question is that when my report executes the functions in the assembly, they execute with the credentials of the server identity. Is there a setting in any config file that I can change so that the assembly can impersonate the current user and execute the functions with the user's credentials?

    Thanks.