DarthVegan
DarthVegan

Reputation: 1269

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()

Upvotes: 5

Views: 16552

Answers (3)

Rodas PT
Rodas PT

Reputation: 339

Came across with the answer on this post How to register CLR assembly as trusted in SSDT deployment that helped me overcome the problem.

I used the script that used the sys.sp_add_trusted_assembly

Upvotes: 0

Solomon Rutzky
Solomon Rutzky

Reputation: 48826

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

Upvotes: 18

user1951575
user1951575

Reputation: 29

Set Premission set field value to Unrestricted.

Upvotes: 0

Related Questions