dimanche 16 août 2015

Load .net dll to w3wp process from sql server database

I have a .net web application that uses a .net dll which contains some functionality.

I'm storing the dll in SQL server DB.

CREATE ASSEMBLY AssemblyName
AUTHORIZATION dbo
FROM 'C:\MyDLLPAth\..\MyDll.dll'
WITH PERMISSION_SET = UNSAFE
GO

I am able to extract it back to a file by Executing:

DECLARE @IMG_PATH VARBINARY(MAX)
DECLARE @ObjectToken INT

SELECT @IMG_PATH = content FROM sys.assembly_files WHERE assembly_id = 65538
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:\ExtractedDLLPAth\..\MyDll.dll', 2
        EXEC sp_OAMethod @ObjectToken, 'Close'
        EXEC sp_OADestroy @ObjectToken

Now, once I have the dll, i can invoke it using reflection from .Net using the Assembly class.

I would like to skip step #2 and load the .net dll from sql server directly to my w3wp process.

Is this possible?





Aucun commentaire:

Enregistrer un commentaire