应用SqlGeometry无法加载sqlserverspatial.dll

最近需要完成一个API,通过用户上传的经纬度判断用户的所在县市省,数据量相对不是很大所以把相关数据全部扔到了内存里知行,主要用到了SqlGeometry,

代码写完后运行本地没问题,扔到服务器上开始报异常“无法加载sqlserverspatial.dll”,一时蛋疼菊紧。难道还得装个sql server的服务吗。。。显然不用- -留下点笔记以备后用。。

Any application that uses Entity Framework’s spatial data type support to target SQL Server requires the ‘CLR Types for SQL Server’ to be available on the machine the application runs on. This also applies to applications that use SQL Server spatial data types directly, without using Entity Framework.(就是说想用SQL Server的空间模块功能一般得装个CLR Types for SQL Server)

When developing your application the CLR Types for SQL Server are usually installed system-wide, since they are included in Visual Studio. Issues arise when you try to deploy to a machine that does not have the CLR Types for SQL Server installed. Initially you will get the following InvalidOperationException.

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

If you were to find and deploy the Microsoft.SqlServer.Types assembly you’ll then get the following DllNotFoundException.

Unable to load DLL 'SqlServerSpatial110.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) ()

(正常思路是引用Microsoft.SqlServer.Types.dll就以为OK了。。然而依然会有异常

解决方案:

安装 Microsoft.SqlServer.Types NuGet package

PM> Install-Package Microsoft.SqlServer.Types
然后项目下出现:
看看readme就啥都解决了。。。
大致就是说想跑起来的话你可以提前加载SqlServerSpatial110.dll这样就不需要装System CLR Types for SQL Server了
然后这个分32位和64位的
然后如果是web可以在程序入口Globle,starup啥的加个 SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
如果是桌面应用啥的就在起始加个SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
 
最近部署时又蹦出来个Bug:
大致意思就是加载这个程序集“Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91“的时候没找到,

打开引用仔细看了看,明明哪里都是版本11.0.0.0

解决方式:

在配置文件中添加对指定程序集

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

 

转载于:https://www.cnblogs.com/ylsforever/p/5159315.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值