locked
SSRS 2008 won't run code from DirectoryServices namespace. RRS feed

  • Question

  • Warning: The Value expression for the textrun ‘Textbox2.Paragraphs[0].TextRuns[0]’ contains an error: Request for the permission of type 'System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed. (rsRuntimeErrorInExpression)

    That is the error. I get.

    I have gone on IIS and set the trust to Full. Downloaded the .NET 2.0 SDK, used the Configuration and set 'All Code' to Full Trust. Web.config has <trust="full">.

    What must I do to make this work?

    Public Function getEmail (byVal userEmail as string) as String 
     
            Dim directory As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry() 
            directory.Path = "LDAP://MailServer" 
            Dim filter As String = "(samaccountname=" & userEmail & ")" 
            Dim findUser As System.DirectoryServices.DirectorySearcher = New System.DirectoryServices.DirectorySearcher(directory, filter) 
            Dim results As System.DirectoryServices.SearchResultCollection = findUser.FindAll 
            Dim UNDisplay, UNVal As String 
            For Each result As System.DirectoryServices.SearchResult In results   
                For Each prop As System.Collections.DictionaryEntry In result.Properties 
                    For Each individualValue As Object In prop.Value 
                        If prop.Key = "samaccountname" Then 
                             UNVal = individualValue.ToString 
     
                        End If 
                        If prop.Key = "mail" Then 
                            UNDisplay = individualValue.ToString 
                        End If 
                    Next 
                Next 
            Next 
     
            return UNDisplay 
     
    End Function 

    Tuesday, March 10, 2009 4:15 PM

Answers

  • Hi newCRMsupport,

    After reproduced the case, the root cause is found that the Report Service use the execution account to access Domain.

    To solve the issue, we can set the "Execution Account" in the page "Execution Account" in Reporting Service Configuration Manager to be a domain user.

    For more information about Execution Account, please see Execution Account (Reporting Services Configuration) in SQL Server Books Online:
    http://msdn.microsoft.com/en-us/library/ms181156.aspx

    If you have any more questions, please feel free to ask.

    Thanks,
    Jin
    Jin Chen - MSFT
    Thursday, March 19, 2009 5:25 AM

All replies

  •  

    Hi newCRMsupport,

     

    Based on my experience, using code to retrieve information from the Directory directly and frequently may cause performance issues. Because there may be many sub domains in your domain, or the structure of domain (organization) is very complex. 

     

    In previous projects, we often use the following solution to solve the issue:

    1.       Program a Windows Service to retrieve information from directory, and then store the information in SQL Server.

    2.       Schedule the Windows Service based on how often the user information is updated.

    3.       Retrieve the information from the DataBase when needed.

     

    If you have any more questions, please feel free to ask.

     

    Thanks,

    Jin


    Jin Chen - MSFT
    Friday, March 13, 2009 2:37 AM
  • Take a look at this documentation - it will explain how SSRS uses code access security.  In your case, you'll need to add a CAS policy to allow calling the methods in that namespace.

     http://msdn.microsoft.com/en-us/library/ms154466(SQL.90).aspx

    -Lukasz
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, March 13, 2009 2:10 PM
  • Hi newCRMsupport,

    After reproduced the case, the root cause is found that the Report Service use the execution account to access Domain.

    To solve the issue, we can set the "Execution Account" in the page "Execution Account" in Reporting Service Configuration Manager to be a domain user.

    For more information about Execution Account, please see Execution Account (Reporting Services Configuration) in SQL Server Books Online:
    http://msdn.microsoft.com/en-us/library/ms181156.aspx

    If you have any more questions, please feel free to ask.

    Thanks,
    Jin
    Jin Chen - MSFT
    Thursday, March 19, 2009 5:25 AM