Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host

I'm using threading in my SQLCLR Project and I'm getting the following error when I try to run my user defined function. What can I do to enable threading things such as the Parallel library and await/async in my project?

Msg 6522, Level 16, State 1, Line 4
A .NET Framework error occurred during execution of user-defined routine or aggregate "CalculateInfo":
  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: Synchronization, ExternalThreading

    System.Security.HostProtectionException:
        at UserDefinedFunctions.getData()
        at UserDefinedFunctions.CalculateInfo()

like image 390
DarthVegan Avatar asked Feb 02 '15 00:02

DarthVegan


1 Answers

This error, as noted in your other question, Deploying SQLCLR project fails when creating assembly in database, requires the following:

ALTER ASSEMBLY [AssemblyName]
   WITH PERMISSION_SET = UNSAFE;

For more information on working with SQLCLR in general, please visit: SQLCLR Info

like image 174
Solomon Rutzky Avatar answered Nov 10 '22 11:11

Solomon Rutzky