简体   繁体   English

在 SQL Server 中加载第 3 方 clr dll

[英]Load 3rd party clr dll in SQL Server

I wrote a SQL CLR function in C# that has some dependency (to npgsql.dll).我在 C# 中编写了一个 SQL CLR 函数,它有一些依赖性(对 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.当它过去没有任何依赖关系时,我可以毫无问题地将它添加为 SQL Server 中的新程序集 - 但现在我不能这样做。

I get this error:我收到此错误:

Msg 10301, Level 16, State 1, Line 17消息 10301,级别 16,状态 1,第 17 行
Assembly 'Database1' references assembly 'system.directoryservices, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database.程序集“Database1”引用程序集“system.directoryservices, version=4.0.0.0,culture=neutral, publickeytoken=b03f5f7f11d50a3a.”,当前数据库中不存在该程序集。 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.)). SQL Server 尝试从引用程序集来自的同一位置定位并自动加载引用程序集,但该操作失败(原因:2(系统找不到指定的文件。))。 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:编辑:这个问题不仅仅是“system.directoryservices”,所以当我使用另一个 npgsql.dll 时,我得到以下错误:

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.消息 10301,级别 16,状态 1,第 20 行程序集“Database1”引用程序集“system.threading.tasks.extensions, version=4.1.0.0,culture=neutral, publickeytoken=cc7b13ffcd2ddd51.”,当前数据库中不存在. 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.)). SQL Server 尝试从引用程序集来自的同一位置定位并自动加载引用程序集,但该操作失败(原因:2(系统找不到指定的文件。))。 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.并且任何使用开发人员命令提示符将这些库添加到 GAC 的尝试都不起作用。

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.在将DirectoryServices DLL 导入 SQL Server(具有一定风险的操作)之前,请确保您实际上无法以任何其他方式执行该功能。 For example:例如:

C# clr udf for Active Directory group membership 用于 Active Directory 组成员身份的 C# clr udf

Otherwise, look here:否则,请看这里:

How to register System.DirectoryServices for use in SQL CLR User Functions? 如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?

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.那里的“修复”是启用TRUSTWORTHY ,这在任何方面都不是一个很好的选择,但它是加载不受支持的 .NET Framework 库的常用方法。 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.我正在研究另一种到目前为止看起来不错并且不需要TRUSTWORTHY ,但我需要做更多的测试才能推荐它。 I will update this later with that info once I have time to fully test and document it.一旦我有时间对其进行全面测试和记录,我将在稍后使用该信息进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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