|
9 | 9 | SELECT * FROM [$(TableName)] |
10 | 10 | -------------------------------------------------------------------------------------- |
11 | 11 | */ |
| 12 | +-- Make sure clr is enabled |
| 13 | +DECLARE @InitAdvanced INT |
| 14 | + |
| 15 | +IF EXISTS (select * from sys.configurations where name IN ('clr enabled') and value_in_use = 0) |
| 16 | +BEGIN |
| 17 | + SELECT @InitAdvanced = CONVERT(int, value) FROM sys.configurations WHERE name = 'show advanced options'; |
| 18 | + |
| 19 | + IF @InitAdvanced = 0 |
| 20 | + BEGIN |
| 21 | + EXEC sp_configure 'show advanced options', 1; |
| 22 | + RECONFIGURE; |
| 23 | + END |
| 24 | + |
| 25 | + IF EXISTS (select * from sys.configurations where name = 'clr enabled' and value_in_use = 0) |
| 26 | + BEGIN |
| 27 | + EXEC sp_configure 'clr enabled', 1; |
| 28 | + RECONFIGURE; |
| 29 | + END |
| 30 | + |
| 31 | + IF @InitAdvanced = 0 |
| 32 | + BEGIN |
| 33 | + EXEC sp_configure 'show advanced options', 0; |
| 34 | + RECONFIGURE; |
| 35 | + END |
| 36 | +END |
| 37 | +GO |
12 | 38 | use [master]; |
13 | 39 | GO |
14 | | -IF NOT EXISTS (select * from sys.asymmetric_keys WHERE name = 'sql_clr_ics_pkey') |
| 40 | +-- Create symmetric key from DLL |
| 41 | +IF NOT EXISTS ( |
| 42 | + select * from master.sys.asymmetric_keys |
| 43 | + WHERE |
| 44 | + name = 'sql_clr_ics_pkey' |
| 45 | + --thumbprint = 0xC5022B1D1415FC7A |
| 46 | + ) |
15 | 47 | create asymmetric key sql_clr_ics_pkey |
16 | 48 | from executable file = '$(PathToSignedDLL)' |
17 | 49 | --encryption by password = 'vtwjmifewVfnhrYke@ZuhxkumsFT7_&#$!~<avjqn|mnvJhp' |
18 | 50 | GO |
19 | | -IF NOT EXISTS (select name from sys.syslogins where name = 'sql_clr_ics_login') |
| 51 | +-- Create server login from symmetric key |
| 52 | +IF NOT EXISTS (select name from master.sys.syslogins where name = 'sql_clr_ics_login') |
20 | 53 | create login sql_clr_ics_login from asymmetric key sql_clr_ics_pkey; |
21 | 54 | GO |
| 55 | +-- Grant UNSAFE ASSEMBLY permissions to login which was created from DLL signing key |
22 | 56 | grant unsafe assembly to sql_clr_ics_login; |
23 | 57 | GO |
24 | 58 | -- Return execution context to intended target database |
|
0 commit comments