SQL Server Performance

CLR Function and Full Trust Question?

Discussion in 'Getting Started' started by lcerni, Dec 3, 2007.

  1. lcerni New Member

    The Developer is attempting to run this code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    public partial class UserDefinedFunctions
    {
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString Function2(string str)
    {
    System.ComponentModel.MaskedTextProvider mm = new System.ComponentModel.MaskedTextProvider("0000");

    // Put your code here
    str = "sdfs fsdf sdf sdf sdf sdf sdf sdf" + str;
    return str;
    }
    };
    When he does, he gets this error message:
    Msg 6522, Level 16, State 2, Line 1
    A .NET Framework error occurred during execution of user defined routine or aggregate 'Function2':
    System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.
    The protected resources (only available with full trust) were: All
    The demanded resources were: SharedState
    System.Security.HostProtectionException:
    at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
    at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
    at UserDefinedFunctions.Function2(String str)

    Is there an option that I must turn on so that the operation IS NOT forbidden by the CLR host? That there is full trust?
    When the Developer runs this code not in a CLR function it works. When he places it into a CLR function it does not work.
  2. satya Moderator

  3. lcerni New Member

    It didn't work. Thank you for pointing me into the correct direction. At least now I am not as lost as I felt before. I will continue to research and if I have further questions I will post them.
  4. lcerni New Member

    It worked when we set PERMISSION_SET to UNSAFE. EXTERNAL_ACCESS did not work for us.

Share This Page