开发者

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

开发者 https://www.devze.com 2023-02-19 06:56 出处:网络
Exception message: Could not load file or assembly System.DirectoryServices or one of its dependencies. Exception from HRESULT: 0x80FC3C2C

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 p开发者_运维问答arameter TRUSTWORTHY set to ON
  4. Assembly created with PERMISSION_SET = UNSAFE


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).


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).


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.


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号