How to register System.DirectoryServices for use in SQL CLR User Functions?(如何注册 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 用户函数中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何注册 System.DirectoryServices 以在 SQL CLR 用户函数
基础教程推荐
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- 创建属性设置器委托 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01