如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?

How to register System.DirectoryServices for use in SQL CLR User Functions?(如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?)
本文介绍了如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在移植一个用 VB6 编写的旧 32-bit COM 组件,用于读取和写入 Active Directory> 服务器.新的解决方案将使用 C# 并将使用 SQL CLR 用户函数.

I am porting an old 32-bit COM component that was written in VB6 for the purpose of reading and writing to an Active Directory server. The new solution will be in C# and will use SQL CLR user functions.

我尝试部署到 SQL Server 的程序集包含对 System.DirectoryServices 的引用.该项目确实编译没有任何错误,但由于以下错误,我无法将程序集部署到 SQL Server:

The assembly that I am trying to deploy to SQL Server contains a reference to System.DirectoryServices. The project does compile without any errors but I am unable to deploy the assembly to the SQL Server because of the following error:

错误:程序集system.directoryservices,version=2.0.0.0,culture=neutral,publickeytoken=b03f5f7f11d50a3a."未在 SQL 目录中找到.

在 SQL Server 上注册 System.DirectoryServices 的正确步骤是什么?

What are the correct steps for registering System.DirectoryServices on SQL Server?

推荐答案

其他答案提供的信息使我找到了解决方案.以下是我想出的步骤以供将来参考:

The information provided from other answers led me to the solution. Here are the steps I came up with for future reference:

CREATE ASSEMBLY [System.DirectoryServices]
FROM 'C:WindowsMicrosoft.NETFrameworkv2.0.50727System.DirectoryServices.dll'
WITH PERMISSION_SET = UNSAFE
GO

我第一次运行上面的语句时出现以下错误:

The first time I ran the statement above I got the following error:

为程序集System.DirectoryServices"创建程序集失败,因为程序集System.DirectoryServices"未授权 PERMISSION_SET = UNSAFE.当以下任一情况为真时,程序集被授权:数据库所有者 (DBO) 具有 UNSAFE ASSEMBLY 权限并且数据库具有 TRUSTWORTHY 数据库属性;或者程序集使用证书或非对称密钥签名,该证书或非对称密钥具有具有 UNSAFE ASSEMBLY 权限的相应登录名.

CREATE ASSEMBLY for assembly 'System.DirectoryServices' failed because assembly 'System.DirectoryServices' is not authorized for PERMISSION_SET = UNSAFE. The assembly is authorized when either of the following is true: the database owner (DBO) has UNSAFE ASSEMBLY permission and the database has the TRUSTWORTHY database property on; or the assembly is signed with a certificate or an asymmetric key that has a corresponding login with UNSAFE ASSEMBLY permission.

为了让 CREATE ASSEMBLY 语句无误地执行,我必须首先按如下方式打开 TRUSTWORTHY:

In order to get the CREATE ASSEMBLY statement to execute without error I had to first turn TRUSTWORTHY ON as follows:

ALTER DATABASE DatabaseName SET TRUSTWORTHY ON
GO

一旦 TRUSTWORTHY 被打开,命令执行没有错误,但它确实出现了这个可怕的警告:

Once TRUSTWORTHY is turned ON, the command executed without error but it did present this scary sounding warning:

警告:Microsoft .NET Framework 程序集system.directoryservices,版本=2.0.0.0,culture=neutral,publickeytoken=b03f5f7f11d50a3a,processorarchitecture=msil."您正在注册的未在 SQL Server 托管环境中进行全面测试且不受支持.将来,如果您升级或维护此程序集或 .NET Framework,您的 CLR 集成例程可能会停止工作.有关详细信息,请参阅 SQL Server 联机丛书.

Warning: The Microsoft .NET Framework assembly 'system.directoryservices, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a, processorarchitecture=msil.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.

在 SQL Server 中正确注册 System.DirectoryServices 后,我现在可以毫无问题地部署/注册依赖的自定义 SQL CLR 程序集.

With System.DirectoryServices properly registered in SQL Server I am now able to deploy/register the dependent custom SQL CLR assembly without any problems.

这篇关于如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
Query From LDAP for User Groups(从 LDAP 查询用户组)
How can I get DOMAINUSER from an AD DirectoryEntry?(如何从 AD DirectoryEntry 获取 DOMAINUSER?)