我正在尝试调用一个 .net 程序集,该程序集包装了来自 Sql Server 的一些 COM 调用(对第三方 dll)。程序集注册正常(我尝试使用不安全和外部访问进行注册),但是当我运行该过程时,出现此错误:
执行用户定义例程或聚合“ManagedCodeCallTest”期间发生 .NET Framework 错误:
System.UriFormatException:无效的 URI:URI 为空。
系统.UriFormatException:
在 System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
在 System.Uri..ctor(String uriString)
在 System.ComponentModel.Design.RuntimeLicenseContext.GetLocalPath(字符串文件名)
在 System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey(类型类型,程序集资源Assembly)
在 System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo(Int32& fDesignTime,IntPtr& bstrKey,RuntimeTypeHandle rth)
在 ManagedCode.MyClass.ArielComponentCall()
有任何想法吗?我想做的事情有可能吗?我读过一些有关许可 dll 的内容,但信息非常模糊。
编辑:CLR 代码以防有帮助:
[SqlProcedure]
public static void ArielComponentCall()
{
Ariel.ApplicationClass application = new Ariel.ApplicationClass();
object arielDoc = application.OpenDocument(@"P:\Projects\COAT\Ariel1.run");
}
包含此类的项目具有对 com 对象的引用。
SQL Server 上的 SqlClr 实现包含a list http://msdn.microsoft.com/en-us/library/ms172338%28v=vs.100%29.aspx可以在 SQL Server 中工作的“有福的”.net 汇编方法。这是通过管理主机保护属性 http://msdn.microsoft.com/en-us/library/system.security.permissions.hostprotectionattribute.aspx。更确切地说
SQL Server 不允许使用具有
指定 HostProtectionResource 值的 HostProtectionAttribute
SharedState、同步、MayLeakOnAbort 或
外部进程管理这可以防止程序集调用成员
启用共享状态、执行同步可能会导致
终止时资源泄漏,或影响 SQL 的完整性
服务器进程。
根据程序集的“访问”设置,SQL Server 将抛出错误(安全时),或者对被阻止的方法不执行任何操作(UNSAFE
and EXTERNAL ACCESS
).
对你来说不幸的是,System.ComponentModel.LicenseContext
类有SharedState
主机保护属性是不允许的代码的一部分。因此,您的代码中的某处会调用 LicenseManager 中的一个方法,该方法将默默地执行任何操作。
无论哪种方式,在 SQL Server 进程中运行 com 组件都不是一个好主意,因为 com 组件崩溃将会导致整个 SQL Server 崩溃。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)