SQLCLR - Wrapping a COM call

我怕爱的太早我们不能终老 提交于 2019-12-10 15:19:27

问题


i'm trying to call a .net assembly that wraps a few COM calls (to a third party dll) from Sql Server. The assembly registers fine (i tried registering with unsafe and external access), but when i run the procedure i get this error:

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

Any ideas? Is what i'm trying to do even possible? I read something about licensed dlls but the information was very vague.

EDIT: CLR code in case it helps:

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

    object arielDoc = application.OpenDocument(@"P:\Projects\COAT\Ariel1.run");
}

The project that contains this class has the reference to the com object.


回答1:


The SqlClr implementation on SQL Server contains a list of "blessed" .net Assembly methods which will work within SQL Server. This is being managed through Host Protection Attributes. More precisely

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.

Depending on the "Access" settings of your assembly SQL Server will throw an error (when SAFE), or do nothing with the blocked method (UNSAFE and EXTERNAL ACCESS).

Unfortunately for you, the System.ComponentModel.LicenseContext class has the SharedState Host Protection Attribute and is part of the code which is not allowed. As a consequence, somewhere in your code there is a call to a method in the LicenseManager which will silently do nothing.

Either way, running com components within the SQL Server process is not a good idea as a crash in the com component will crash your entire SQL Server.



来源:https://stackoverflow.com/questions/6524322/sqlclr-wrapping-a-com-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!