无法加载文件或程序集…或其依赖项之一。 HRESULT 异常:0x80FC3C2C

发布于 2024-10-26 10:06:01 字数 346 浏览 5 评论 0原文

异常消息:无法加载文件或程序集 System.DirectoryServices 或其依赖项之一。 HRESULT 异常:0x80FC3C2C

CLR SQL 过程引发异常。从程序集中的方法引发异常,其中初始化了 System.DirectoryServices 中的类之一,并且该程序集由具有 CLR 过程的程序集使用。

环境:

  1. MS SQL Server 2005 标准。
  2. .NET Framework 2.0
  3. 创建程序集的
  4. 数据库将参数 TRUSTWORTHY 设置为 ON使用 PERMISSION_SET = UNSAFE 创建的程序集

Exception message: Could not load file or assembly System.DirectoryServices or one of its dependencies. Exception from HRESULT: 0x80FC3C2C

Exception raised from CLR SQL procedure. Exception raised from the method in the assembly where one of the classes from System.DirectoryServices is initialized and that assembly is used by the assembly with CLR procedure.

Environment:

  1. MS SQL Server 2005 Std.
  2. .NET framework 2.0
  3. Database where assembly is created has parameter TRUSTWORTHY set to ON
  4. Assembly created with PERMISSION_SET = UNSAFE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风为裳 2024-11-02 10:06:01

就我而言,问题与数据库的所有者有关。

当您遇到此错误时,这种情况也经常发生。
恢复数据库后,修复主数据库中的数据库所有者可能会有所帮助:

--Update db owner in master database
DECLARE @Command VARCHAR(MAX) = 'ALTER AUTHORIZATION ON DATABASE::[<<DatabaseName>>] TO 
[<<LoginName>>]' 

SELECT @Command = REPLACE(REPLACE(@Command 
            , '<<DatabaseName>>', SD.Name)
            , '<<LoginName>>', SL.Name)
FROM master..sysdatabases SD 
JOIN master..syslogins SL ON  SD.SID = SL.SID
WHERE  SD.Name = DB_NAME()

PRINT @Command
EXEC(@Command)

如果这没有帮助,还请尝试以下操作:

ALTER AUTHORIZATION ON DATABASE::[YourDatabaseName] TO [sa]

In my case the issue was related to the owner of the database.

It happens pretty often too when you face this error.
After restore of db it might help to fix db owner in master database:

--Update db owner in master database
DECLARE @Command VARCHAR(MAX) = 'ALTER AUTHORIZATION ON DATABASE::[<<DatabaseName>>] TO 
[<<LoginName>>]' 

SELECT @Command = REPLACE(REPLACE(@Command 
            , '<<DatabaseName>>', SD.Name)
            , '<<LoginName>>', SL.Name)
FROM master..sysdatabases SD 
JOIN master..syslogins SL ON  SD.SID = SL.SID
WHERE  SD.Name = DB_NAME()

PRINT @Command
EXEC(@Command)

If this does not help, try the following also:

ALTER AUTHORIZATION ON DATABASE::[YourDatabaseName] TO [sa]
一桥轻雨一伞开 2024-11-02 10:06:01

请记住,这个答案来自我的培训班笔记...您必须将 PERMISSION_SET 设置为 EXTERNAL_ACCESS 才能访问服务器的文件系统或访问另一台服务器。这是有道理的,因为您正在使用 System.DirectoryServices 访问另一台服务器(域控制器)。

Keep in mind this answer is from my notes from a training class ... You have to set PERMISSION_SET to EXTERNAL_ACCESS to access the server's file system or to access another server. This would make sense since you are using System.DirectoryServices to access another server (the domain controller).

怪我鬧 2024-11-02 10:06:01

我认为 SQL Server 内部根本不支持 System.DirectoryServices 程序集。 SQL Server 只允许非常具体(硬编码)的程序集列表 (SQL Server 2005SQL Server 2008 )的使用,以免损害其稳定性。

话虽如此,似乎有一种方法可以实现它,无论如何请参阅问题/答案(没有尝试过)。

I think System.DirectoryServices assembly is simply not supported inside SQL Server. SQL Server does only allow a very specific (hardcoded) list of assemblies (SQL Server 2005, SQL Server 2008) to be used, in order to not jeopardize it's stability.

Having said that, there seems to be a way to achieve it anyway see this question/answer (haven't tried it).

只是一片海 2024-11-02 10:06:01

最后,我找到了解决方法。我将对 System.DirectoryServices 的引用添加到链接到 MS SQL 的程序集中,并在 CLR 过程代码中从该命名空间创建一个类。因此,System.DirectoryServices 程序集从放置 DS 主要代码的类中变得可见。

Finally, I found the workaround. I added the reference to the System.DirectoryServices to the assembly that is linked to the MS SQL and in the CLR procedure code create a class from this namespace. And so System.DirectoryServices assembly became visible from the class where the main code for DS is placed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文