2017-07-26 55 views
1

問題很簡單。我將WebApps項目移至安裝了Microsoft.SqlServer.Types nuget軟件包的Service Fabric。現在,當試圖訪問數據庫時,我收到以下錯誤,因爲我正在使用空間類型。帶服務結構的Microsoft.SqlServer.Types

「空間類型和功能不適用於該供應商是因爲程序集‘Microsoft.SqlServer.Types’10或更高版本找不到。」

我試着加入以下一行代碼添加到FabricRuntime創建實例的類中,但沒用。

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory); 

您的幫助將不勝感激,請讓我知道如果您需要我的更多信息。

回答

1

你確實需要的代碼行,但對於asp.net應用程序應該是略有不同: 對於Asp.net網站,Default.aspx.cs:

public partial class _Default : System.Web.UI.Page 
{ 
    static bool _isSqlTypesLoaded = false; 

    public _Default() 
    { 
     if (!_isSqlTypesLoaded) 
     { 
      SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~")); 
      _isSqlTypesLoaded = true; 
     } 

    } 
} 

對於Web應用程序,在全球.asax.cs:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin")); 

而且你需要在web.config中創建以下綁定重定向:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
     <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" /> 
    </dependentAssembly> 
    </assemblyBinding> 
</runtime> 

Here是關於該主題的唯一幫助。

更新:Here是一個博客文章,提供了一個很好的描述解決方案的3個步驟。雖然第三步不適用於我,但我必須如上所述創建綁定。

+0

謝謝!這個問題的一個小的變化固定我的問題,你可以在這裏找到它:https://github.com/Azure/service-fabric-issues/issues/369 – haseebahmed7