我正在尝试从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:\Projects\COAT\Ariel1.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崩溃.