11

Tôi đang chuyển một thành phần 3 2-bit COM cũ được viết bằng VB6 để đọc và ghi vào máy chủ Active Directory. Giải pháp mới sẽ ở số C# và sẽ sử dụng SQL CLR chức năng người dùng.Cách đăng ký System.DirectoryServices để sử dụng trong SQL CLR Chức năng người dùng?

Hội đồng mà tôi đang cố triển khai đến SQL Server chứa tham chiếu đến System.DirectoryServices. Dự án không biên dịch mà không cần bất kỳ lỗi nhưng tôi không thể triển khai lắp ráp cho SQL Server vì lỗi sau:

Error: Assembly 'system.directoryservices, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' was not found in the SQL catalog.

các bước chính xác cho việc đăng ký System.DirectoryServices trên SQL Server là gì?

Trả lời

7

Thông tin được cung cấp từ các câu trả lời khác đã dẫn tôi đến giải pháp. Dưới đây là các bước tôi đã đưa ra để tham khảo trong tương lai:

CREATE ASSEMBLY [System.DirectoryServices] 
FROM 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll' 
WITH PERMISSION_SET = UNSAFE 
GO 

Lần đầu tiên tôi chạy báo cáo kết quả trên, chúng tôi đã nhận lỗi sau:

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.

Để có được câu lệnh CREATE HỘI để thực hiện mà không có lỗi Tôi đã phải lần lượt TRUSTWORTHY ON như sau:

ALTER DATABASE DatabaseName SET TRUSTWORTHY ON 
GO 

Khi TRUSTWORTHY được bật ON, lệnh được thực hiện không có lỗi nhưng nó đã trình bày cảnh báo âm thanh đáng sợ này:

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.

Với hệ thống.DirectoryServices được đăng ký đúng cách trong SQL Server Tôi bây giờ có thể triển khai/đăng ký lắp ráp SQL CLR tùy chỉnh phụ thuộc mà không có bất kỳ vấn đề nào.

3

Bài viết đó có trợ giúp không?

New "SQLCLR-approved" assembly in SP1

People often ask about the set of base class library assemblies that can be safely used in SQLCLR. It usually takes the form "can I use assembly System.XYZ.dll in SQLCLR procedural code" or "why do I get "assembly System.XYZ.dll is not found" when I try and catalog my own assembly that calls this one? The ones is hear mentioned most frequently is System.DirectoryServices.dll (Active Directory support) or System.Management.dll (WMI support) or System.Remoting.dll et al. The only way you use these is to run CREATE ASSEMBLY on them yourself, which involves using PERMISSION_SET = UNSAFE. And cataloging all the dependencies. Not for the faint of heart.

Ngoài ra - SQL Server CLR không hỗ trợ tất cả các assembly imagineable - tìm danh sách ở đây:

Một lưu ý từ đó Bài viết thứ hai của MSDN:

Unsupported Libraries

Unsupported libraries can still be called from your managed stored procedures, triggers, user-defined functions, user-defined types, and user-defined aggregates. The unsupported library must first be registered in the SQL Server database, using the CREATE ASSEMBLY statement, before it can be used in your code. Any unsupported library that is registered and run on the server should be reviewed and tested for security and reliability.

For example, the System.DirectoryServices namespace is not supported. You must register the System.DirectoryServices.dll assembly with UNSAFE permissions before you can call it from your code. The UNSAFE permission is necessary because classes in the System.DirectoryServices namespace do not meet the requirements for SAFE or EXTERNAL_ACCESS. For more information, see CLR Integration Programming Model Restrictions and CLR Integration Code Access Security.

0

Muốn thêm điều đó, tôi đã dành một ngày cố gắng đăng ký một hội đồng bằng cách sử dụng khóa không đối xứng đã ký DLL thất bại với lỗi.

. . . is not authorized for PERMISSION_SET = UNSAFE. The assembly is authorized when . . .

CREATE ASYMMETRIC KEY AsyKeyName FROM executable FILE = 'C:\Program Files\...' 

Sau đó chỉ để tìm ra rằng SQL server không thích những con đường với không gian ở giữa !!

Các vấn đề liên quan