SQL SERVER 2016 匯出SQL CLR組件

  • 113
  • 0

因工作需求怕匯入的組件與版控上的不同,於是需匯出並用ILSPY查看內容

--找出組件號碼
SELECT *
FROM sys.assembly_files

--啟用 OLE Automation Procedures
EXEC sp_configure 'Ole Automation Procedures', 1;

--匯出組件資訊
DECLARE @IMG_PATH VARBINARY(MAX)
DECLARE @ObjectToken INT

SELECT @IMG_PATH = content FROM sys.assembly_files WHERE assembly_id = 65544

EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
        EXEC sp_OASetProperty @ObjectToken, 'Type', 1
        EXEC sp_OAMethod @ObjectToken, 'Open'
        EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @IMG_PATH
        EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, 'c:\temp\myassembly.dll', 2
        EXEC sp_OAMethod @ObjectToken, 'Close'
        EXEC sp_OADestroy @ObjectToken