4
votes

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

1 Answers

2
votes

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.