Skip to content

Commit 1fabdbd

Browse files
authored
Making the deployment script portable
Embedding the assembly bytes in the deployment script to make it portable, and support Managed Instance
1 parent 6929800 commit 1fabdbd

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

samples/features/sql-clr/Curl/SqlClrCurl.tt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@ DROP ASSEMBLY IF EXISTS SqlClrCurl;
3232
GO
3333

3434

35+
DECLARE @assembly VARBINARY(MAX) = <#= "0x" + BitConverter.ToString(System.IO.File.ReadAllBytes(this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll"))).Replace("-","") #>
3536
DECLARE @hash VARBINARY(64);
36-
SELECT @hash = HASHBYTES('SHA2_512', BulkColumn)
37-
FROM OPENROWSET(BULK '<#= this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll") #>', SINGLE_BLOB) AS assembly_content
37+
SELECT @hash = HASHBYTES('SHA2_512', @assembly)
3838

39-
IF(@hash IS NOT NULL)
39+
IF(not exists (select * from sys.trusted_assemblies where hash = @hash))
4040
EXEC sp_add_trusted_assembly @hash, N'SqlClrCurl'
4141
ELSE
42-
PRINT 'Cannot create hash for assembly!'
43-
GO
42+
print 'Hash already exists'
4443

4544
--Create the assembly
4645
CREATE ASSEMBLY SqlClrCurl
47-
FROM '<#= this.Host.ResolvePath("bin\\Release\\SqlClrCurl.dll") #>'
46+
FROM @assembly
4847
WITH PERMISSION_SET = EXTERNAL_ACCESS;
4948
GO
5049

@@ -60,4 +59,4 @@ GO
6059

6160
CREATE PROCEDURE CURL.XPOST (@H NVARCHAR(MAX), @d NVARCHAR(MAX), @url NVARCHAR(4000))
6261
AS EXTERNAL NAME SqlClrCurl.Curl.Post;
63-
GO
62+
GO

0 commit comments

Comments
 (0)