Question

I am thinking of using SQL CLR to open a external file. Is this possible? I have not tried this and not aware of it's limitations.

Please suggest if 1) it's possible 2) Is it advisable or against best practise?

Thanks!

Was it helpful?

Solution

Yes you tottaly can! And it's fine.

But you need to define your assembly with external access permission set(in assembly creation query, or at assembly properties):

CREATE ASSEMBLY [BLABLABLA]
FROM 0x4D.............
WITH PERMISSION_SET = EXTERNAL_ACCESS

Also for using this, TRUSTWORTHY property must be set ON, or code-signed as this article says:

EXTERNAL_ACCESS addresses scenarios in which the code needs to access resources outside the server, such as files, network, registry, and environment variables. Whenever the server accesses an external resource, it impersonates the security context of the user calling the managed code.

To create an EXTERNAL_ACCESS or UNSAFE assembly in SQL Server, one of the following two conditions must be met:

  1. The assembly is strong name signed or Authenticode signed with a certificate. This strong name (or certificate) is created inside SQL Server as an asymmetric key (or certificate), and has a corresponding login with EXTERNAL ACCESS ASSEMBLY permission (for external access assemblies) or UNSAFE ASSEMBLY permission (for unsafe assemblies).

  2. The database owner (DBO) has EXTERNAL ACCESS ASSEMBLY (for EXTERNAL ACCESS assemblies) or UNSAFE ASSEMBLY (for UNSAFE assemblies) permission, and the database has the TRUSTWORTHY Database Property set to ON.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top