I'm trying to do a POC using Sqlclr and C# to call .Net code (dll) from a stored procedure. I'm trying to write to EventLogs. I was able to create a safe assembly and then create a stored procedure wrapper around my dll. But while executing the code it failed - for Event Log access the Assembly needs to be created with an External_Access/ Unsafe permission set.
When I tried the same with an External Assembly it didn't work. So I went with the route of creating a Login from the signed dll.
I signed the dll using Visual Studio. Under project properties signing tab, I signed it without a password (snk file).
I then created an asymmetric key in sql with the dll.
Msg 300 - External Access Assembly Permission was denied on object 'server', database 'master'
My question is does my Windows authenticated login need to have more permissions to be able to set the External_Access permissions. Does it require an SA account?
First of all, did you mean to run this on master (as per the error message)?
To use TRUSTWORTHY
, the user needs sysadmin as per here, but it is generally a bad idea to use TRUSTWORTHY
.
To create an assembly with EXTERNAL_ACCESS
the login needs EXTERNAL ACCESS ASSEMBLY permission on the server. To create the assembly as UNSAFE
the login needs UNSAFE ASSEMBLY permission on the server. You can read more about that here.
Niels