2012-11-01 107 views
57

我试图在ASP.NET MVC 4中创建一个webapi。使用了实体框架5的webapi空间类型和我写了一个非常简单码。在Azure上找不到'Microsoft.SqlServer.Types'版本10或更高版本

public List<Area> GetAllAreas() 
    { 
     List<Area> aList = db.Areas.ToList(); 
     return aList; 
    } 

Area包含DbGeometry。

当我运行这个地方它的工作原理,但是当我发布到Azure它给了我这个错误:

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

任何人都知道如何解决这个问题? :)

谢谢!

+2

是否使用Azure网站或云服务Web角色固定我的问题?另外,你的数据库是一个SQL Azure数据库吗?您是否尝试过针对SQL Azure数据库运行本地代码,并且这是否正常工作? –

回答

102

我找到了解决方案!只需安装NuGet包Microsoft.SqlServer.Types

PM> Install-Package Microsoft.SqlServer.Types

Link for more info

+2

谢谢。这件事发生在凌晨2点后,就发生在我身上。 –

+3

很高兴我把那个nuget包装起来!它也总是让我感动。 OMG! –

+0

OMG!它向Web应用程序添加了将近2MB的二进制数据,仅用于使用DbGeography(不,谢谢),在SQL Server中使用它时CPU也很重要......将其取出。 – Yovav

12

我也遇到了这个问题,但已经安装了Microsoft.SqlServer.Types NuGet包。

什么解决了我的问题是解决>参考> System.Data.Entity>属性>复制本地,并将其设置为True。

注: 复制本地的Microsoft.SqlServer.Types已经被设置为true,即使该问题是与System.Data.Entity的,错误消息是仍有约Microsoft.SqlServer.Types。

该解决方案来自Windows Azure forum

+1

该选项在nuget包中不可用。 – Shimmy

2

的解决方案,我刚加入这行代码的Global.asax.cs在Application_Start()

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

祝我的兄弟。

1

上述解决方案都不能解决我的问题。

  • 安装SQL Server Feature Pack?是的
  • NuGet包安装?是的
  • DLL存在于GAC和项目bin中?是

你知道吗,这个错误也可能是由于服务器上的资源不足。我重新启动了SQL Server并自动解析。

51

上述answer在可以使用程序集的版本11(SQL Server 2012)时正常工作。

我遇到了问题,因为我的解决方案对同一程序集的版本13(SQL Server 2016)具有其他依赖关系。在这种情况下,请注意实体框架(至少v6.1.3)在其SqlTypesAssemblyLoader(此例外源)中进行了硬编码,仅查找程序集的版本10和11。

若要解决此,我发现你可以告诉实体框架要使用像这样在装配:

SqlProviderServices.SqlServerTypesAssemblyName = 
    "Microsoft.SqlServer.Types, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"; 
+1

好点 - 同样适用于只安装SQL 2014 CLR类型的机器。在我们的例子中,我们刚刚安装了SQL 2012 CLR类型并解决了问题;但如果您对组件的高版本有特定的依赖关系,那么这看起来是最好的解决方案。 –

+0

该值应该在何时/何时设定? – Triynko

+1

这是一个静态公共财产。它应该在应用程序启动时设置。例如。我将其设置在我的Web应用程序的Global.asax.cs中的Application_Start事件中。 – Chris

0

刚刚有同样的问题。我正在使用EF6并调用SQL,它具有使用空间命令的SQL函数。我通过单元测试来测试它,它工作正常。当我去到线了我Asp.Net的解决方案,我收到了错误

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

通过添加NUGET包“Microsoft.SqlServer.Types”和添加SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));Application_Start methodGlobal.asax.cs,一切运行良好。

14

有2种方法来解决这个问题:

  1. 如果您有服务器访问,只需要安装“微软系统CLR类型的SQL Server 2012” 从https://www.microsoft.com/en-us/download/details.aspx?id=29065 或使用直接链接的下面 直接链接到X86:http://go.microsoft.com/fwlink/?LinkID=239643&clcid=0x409 ,或者直接链接到X64:http://go.microsoft.com/fwlink/?LinkID=239644&clcid=0x409
  2. 第二种方式是使用NuGet包管理器,安装于

    安装,包装Microsoft.SqlServer.Types

然后按照该插件注意事项如下

To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial110.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr100.dll is also included in case the C++ runtime is not installed.

You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).

ASP.NET applications For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:

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

Desktop applications For desktop applications, add the following line of code to run before any spatial operations are performed:

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

安装SQL Server或NuGet没有解决任何问题,这些简单的CLR类型解决了这个问题。这应该是可以接受的解决方案。 –

+0

链接到X64对我有用 Microsoft SQL Server 2016(SP1)(KB3182545) - 13.0.4001.0(X64)Oct 28 2016 18:17:30 Copyright(c)Microsoft Corporation Express Edition(64-bit)on Windows 10 Enterprise 6.3 (Build 10586:) – zapoo

+0

我需要使用ASP.NET样式加载器,但是我的开发路径是'〜/'而不是'〜/ bin'。一定要检查你的路径。 – jocull

0

在我的情况下,严重组成连接字符串导致此。验证您的连接字符串是否正确组成。

22

由于某种原因,我错过了一个绑定重定向,它为我解决了这个问题。

添加以下

<dependentAssembly> 
     <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> 
     <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" /> 
    </dependentAssembly> 
+0

为了找出你的机器上的Microsoft.SqlServer.Types版本号是什么,你可以使用'AppDomain currentDomain = AppDomain.CurrentDomain;程序集[] assems = currentDomain.GetAssemblies(); foreach(程序集中的程序集程序集) _logger.Info(assembly.GetName()。FullName); }'_logger是一个Nlog日志记录器 –

+0

这解决了我的问题(因为类型已经安装在我的情况)。如果有人在安装SQL Server类型后仍然出现错误,请检查此答案。 –

相关问题