简体   繁体   中英

Load 3rd party clr dll in SQL Server

I wrote a SQL CLR function in C# that has some dependency (to npgsql.dll). When it didn't have any dependency in the past, I can add it as a new assembly in SQL Server without any problem - but now I can't do it.

I get this error:

Msg 10301, Level 16, State 1, Line 17
Assembly 'Database1' references assembly 'system.directoryservices, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2 (The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

Edited: This problem is not just with 'system.directoryservices', so when i use another npgsql.dll i get following error instead:

Msg 10301, Level 16, State 1, Line 20 Assembly 'Database1' references assembly 'system.threading.tasks.extensions, version=4.1.0.0, culture=neutral, publickeytoken=cc7b13ffcd2ddd51.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

and any try to add these library to GAC with Developer Command Prompt doesn't work.

This question has been asked and answered several times already on here. But, rather than just listing this as a duplicate, something needs to be said first:

Before importing the DirectoryServices DLL into SQL Server (an action that has some amount of risk), be sure that you actually can't go about that functionality in any other way. For example:

C# clr udf for Active Directory group membership

Otherwise, look here:

How to register System.DirectoryServices for use in SQL CLR User Functions?

The "fix" there is to enable TRUSTWORTHY , which isn't a great option by any stretch, but it is the common way to get unsupported .NET Framework libraries loaded. I am working on another means that is so far looking good and doesn't require TRUSTWORTHY , but I need to do a little more testing before I can recommend it. I will update this later with that info once I have time to fully test and document it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM