gpt4 book ai didi

c# - SQLCLR - 包装 COM 调用

转载 作者:行者123 更新时间:2023-11-30 12:34:53 25 4
gpt4 key购买 nike

我正在尝试调用一个 .net 程序集,它包装了来自 Sql Server 的几个 COM 调用(对第三方 dll)。程序集注册正常(我尝试使用不安全和外部访问注册),但是当我运行该过程时出现此错误:

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:\Projects\COAT\Ariel1.run");
}

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

最佳答案

SQL Server 上的 SqlClr 实现包含 a list将在 SQL Server 中工作的“有福的”.net 程序集方法。这是通过 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 将抛出错误(当安全时),或者对被阻止的方法不执行任何操作(UNSAFEEXTERNAL ACCESS ).

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

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

关于c# - SQLCLR - 包装 COM 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524322/

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