Why is the SQLCLR code only partially trusted?
By default, the CLR code running inside SQL Server (ie, "SQLCLR") is severely limited so as not to impair the security or stability of SQL Server.
How to make SQLCLR fully trust?
What the CLR code in the assembly can do is controlled (mainly) by using the PERMISSION_SET property for each assembly. If you do not specify PERMISSION_SET when loading the assembly through CREATE ASSEMBLY , the default will be SAFE , which is the most limited and not fully trusted. In order for the CLR code to go beyond SQL Server (to the network, file system, OS, etc.), you need to set Assembly to at least EXTERNAL_ACCESS , but it is still not fully trusted. To be considered fully trusted , you need to install Assembly on UNSAFE .
To set any assembly to EXTERNAL_ACCESS or UNSAFE , you need to do one of the following:
- Set the database containing the assembly to TRUSTWORTHY = ON. This assumes that the database owner has
UNSAFE ASSEMBLY permission at the server level (this is usually the case). Although this option is faster / simpler, it is not preferred because TRUSTWORTHY = ON is a fairly wide open security hole. - Sign the assembly with a password, create an asymmetric key from the assembly, create an input from an asymmetric key, provide a login to the
UNSAFE ASSEMBLY system. This is the preferred method.
If you want to learn more about SQLCLR security, especially with regard to how SAFE builds are limited, see the article that I wrote in SQL Server Central (free registration is required to read articles on this site).
source share