2011-06-29 53 views
4

我試圖調用一個.net程序集,它包裝了一些來自Sql Server的COM調用(第三方DLL)。該組件註冊罰款(我試着用不安全和外部訪問註冊),但是當我運行程序我得到這個錯誤:SQLCLR - 包裝COM調用

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對象的項目。

回答

2

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),或者什麼也不做與阻斷法(UNSAFEEXTERNAL ACCESS)。

不幸的是,System.ComponentModel.LicenseContext類具有SharedState主機保護屬性,並且是不允許的代碼的一部分。因此,在你的代碼的某個地方有一個對LicenseManager中的方法的調用,它將默默無聞地執行任何操作。

無論採用哪種方式,在SQL Server進程中運行com組件都不是一個好主意,因爲com組件中的崩潰會導致整個SQL Server崩潰。