/* ===================================== SQL-CLR-ICS Installation Script ===================================== Source: https://github.com/EitanBlumin/sql_clr_ics License: MIT (https://github.com/EitanBlumin/sql_clr_ics/blob/master/LICENSE) --------------------------------------------------- Run this script within any database where you want to create the sql_clr_ics assembly and accompanying procedures. ---------------------------------- ! Run this script in SQLCMD Mode ! ---------------------------------- Set the PathToSignedDLL variable to the path for the signed DLL file */ SET NOEXEC OFF; GO SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; SET NUMERIC_ROUNDABORT OFF; :setvar PathToSignedDLL "C:\SqlClrIcs\sql_clr_ics.dll" GO :on error exit GO /* Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported. To re-enable the script after enabling SQLCMD mode, execute the following: SET NOEXEC OFF; */ :setvar __IsSqlCmdEnabled "True" GO IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True' BEGIN PRINT N'SQLCMD mode must be enabled to successfully execute this script.'; SET NOEXEC ON; END GO -- Make sure CLR is enabled DECLARE @InitAdvanced INT IF EXISTS (select * from sys.configurations where name IN ('clr enabled') and value_in_use = 0) BEGIN PRINT N'Enabling CLR instance configuration...' SELECT @InitAdvanced = CONVERT(int, value) FROM sys.configurations WHERE name = 'show advanced options'; IF @InitAdvanced = 0 BEGIN EXEC sp_configure 'show advanced options', 1; RECONFIGURE; END IF EXISTS (select * from sys.configurations where name = 'clr enabled' and value_in_use = 0) BEGIN EXEC sp_configure 'clr enabled', 1; RECONFIGURE; END IF @InitAdvanced = 0 BEGIN EXEC sp_configure 'show advanced options', 0; RECONFIGURE; END END GO -- Create symmetric key from signed DLL IF NOT EXISTS (select * from master.sys.asymmetric_keys WHERE name = 'sql_clr_ics_pkey' --thumbprint = 0xC5022B1D1415FC7A ) BEGIN PRINT N'Creating assymetric key from signed DLL...' EXEC master..sp_executesql N' CREATE ASYMMETRIC KEY sql_clr_ics_pkey FROM EXECUTABLE FILE = ''$(PathToSignedDLL)'' --ENCRYPTION BY PASSWORD = ''vtwjmifewVfnhrYke@ZuhxkumsFT7_&#$!~