gpt4 book ai didi

sql-server-2005 - Sql 2005 CLR 集成 - 是否支持动态程序集加载?

转载 作者:行者123 更新时间:2023-12-04 07:01:45 25 4
gpt4 key购买 nike

我有一个静态类,它动态加载 .NET 程序集(使用 Assembly.LoadFile 方法)
我收到以下错误消息:

Msg 6522, Level 16, State 2, Line 3
A .NET Framework error occurred during execution of user-defined routine or aggregate "MySQLCLRUDFFunction":
System.TypeInitializationException: The type initializer for 'MyClassName' threw an exception. ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

.

当我尝试使用此声明分配 CAS 安全性时
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]

我反而得到这个异常(exception)
Msg 6522, Level 16, State 2, Line 2
A .NET Framework error occurred during execution of user-defined routine or aggregate "MySQLCLRUDFFunction":
System.TypeInitializationException: The type initializer for 'MyClassName' threw an exception. ---> System.Security.SecurityException: Request failed.

注意:我已为我的 SQL Server 服务帐户提供了对磁盘上动态程序集文件的“完全访问权限”。我使用语法复制了我的动态程序集:
create Assembly TestAssembly
From 'C:\MyTestAssembly.dll';
--Alter Assembly to copy dynamic assembly file
Alter Assembly TestAssembly add file from 'C:\mydynamicassembly.dll';

转后 TRUSTWORTHY ON和设置 PERMISSION_SET = UNSAFE我现在得到这个异常(exception)
Msg 6522, Level 16, State 2, Line 2
A .NET Framework error occurred during execution of user-defined routine or aggregate "MySQLCLRUDFFunction":
System.TypeInitializationException: The type initializer for 'MyClassName' threw an exception. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.

最佳答案

正如错误消息所述,SQL Server 完全不允许动态程序集加载 - 即使在不安全的情况下也是如此。 Assembly.Load 调用成功的唯一方法是,如果程序集已经通过 CREATE ASSEMBLY 或 GAC 和 list of supported ("blessed") assemblies 加载到数据库中。 .在 sqlclr blog 上还有一篇关于此的帖子。 .

关于sql-server-2005 - Sql 2005 CLR 集成 - 是否支持动态程序集加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1723414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com