I have a CLR assembly in SQL Server which I need to inherit a particular account's permissions. The CLR function basically just grabs a webpage and returns it to SQL in this fashion:
[SqlFunction] [return: SqlFacet(MaxSize = -1)] public static SqlChars Get(SqlChars H, SqlChars url) { var client = new WebClient(); client.Credentials = CredentialCache.DefaultNetworkCredentials; AddHeader(H, client); return new SqlChars( client.DownloadString( Uri.EscapeUriString(url.ToSqlString().Value) ).ToCharArray()); } I want that to be able to authenticate via NTLM using a specific accounts details. This works fine in a C# program outside SQL but as a CLR function it just returns 401 Unauthorized messages, which is because the DefaultNetworkCredentials are those of the SQL Server Service account (I confirmed this by setting the service to use MY credentials, and the CLR then worked perfectly)
My understanding is that the way to do this is create a Credential in SQL Server with that account's details, since that's what the documentation says:
Credentials provide a way to allow SQL Server Authentication users to have an identity outside of SQL Server. This is primarily used to execute code in Assemblies with EXTERNAL_ACCESS permission set.
I can do that, but what I can't seem to do is find any way to map that credential to the assembly. How do I do that?