加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – SQLCLR – 包装COM调用

发布时间:2020-12-15 17:18:10 所属栏目:百科 来源:网络整理
导读:我正在尝试从Sql Server调用一个包含几个COM调用(到第三方dll)的.net程序集.程序集注册正常(我尝试注册不安全和外部访问),但是当我运行该程序时,我收到此错误: A .NET Framework error occurred during execution of user-defined routine or aggregate “M
我正在尝试从Sql Server调用一个包含几个COM调用(到第三方dll)的.net程序集.程序集注册正常(我尝试注册不安全和外部访问),但是当我运行该程序时,我收到此错误:

A .NET Framework error occurred during execution of user-defined routine or aggregate “ManagedCodeCallTest”:
System.UriFormatException: Invalid URI: The URI is empty.
System.UriFormatException:
at System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)
at System.Uri..ctor(String uriString)
at System.ComponentModel.Design.RuntimeLicenseContext.GetLocalPath(String fileName)
at System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey(Type type,Assembly resourceAssembly)
at System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo(Int32& fDesignTime,IntPtr& bstrKey,RuntimeTypeHandle rth)
at ManagedCode.MyClass.ArielComponentCall()

有任何想法吗?我正在努力做甚么可能吗?我阅读了有关许可dll的内容,但信息非常模糊.

编辑:CLR代码,以防它有帮助:

[SqlProcedure]
public static void ArielComponentCall()
{
    Ariel.ApplicationClass application = new Ariel.ApplicationClass();

    object arielDoc = application.OpenDocument(@"P:ProjectsCOATAriel1.run");
}

包含此类的项目具有对com对象的引用.

解决方法

SQL Server上的SqlClr实现包含 a list个“祝福”的.net程序集方法,它们可以在SQL Server中运行.这是通过 Host Protection Attributes管理的.更确切地说

SQL Server disallows the use of a type or member that has a
HostProtectionAttribute that specifies a HostProtectionResource value
of SharedState,Synchronization,MayLeakOnAbort,or
ExternalProcessMgmt. This prevents the assemblies from calling members
that enable sharing state,perform synchronization,might cause a
resource leak on termination,or affect the integrity of the SQL
Server process.

根据程序集的“访问”设置,SQL Server将抛出错误(当SAFE时),或者对阻止的方法(UNSAFE和EXTERNAL ACCESS)不执行任何操作.

不幸的是,System.ComponentModel.LicenseContext类具有SharedState主机保护属性,并且是不允许的代码的一部分.因此,在代码中的某个位置会调用LicenseManager中的方法,该方法将无声地执行任何操作.

无论哪种方式,在SQL Server进程中运行com组件都不是一个好主意,因为com组件中的崩溃将导致整个SQL Server崩溃.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读