WEB API 使用空间数据类型 发布出错
2016-01-06 16:10
260 查看
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服务器安装在程序所发布的服务器上。但是也有一种方式可以直接使用空间数据类型而不需要安装SQL数据库。减少环境的依赖性。
在网上查找很多资料,都不能得到良好的解决。
问题是这样的,我的API服务使用了空间数据类型 DbGeography和DbGeometry ,本来发布在一个服务器上一切运行正常,后来发布到另一个服务器上之后,发现如下错误:
经历的波折就不多说了,先把解决方案给出:
step1:NuGet package.
Microsoft.SqlServer.Types
dependency. Includes the unmanaged dependency SqlServerSpatial.dll in the package 'tools' directory.
其中包含我们所需要的两个程序集:Microsoft.SqlServer.Types
.dll 和 SqlServerSpatial.dll
下面是该安装包中,两个程序集的具体位置
下面的这个程序集是不可被引用的
一定要注意程序集的版本信息要与该配置文件设定一致
找不到第二个程序集,这也无可厚非,毕竟没有添加到当前项目,发布的时候也不会有该程序集。因为这个程序集是不可添加的。
也没有找到很好的解决方案。
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服务器安装在程序所发布的服务器上。但是也有一种方式可以直接使用空间数据类型而不需要安装SQL数据库。减少环境的依赖性。
在网上查找很多资料,都不能得到良好的解决。
问题是这样的,我的API服务使用了空间数据类型 DbGeography和DbGeometry ,本来发布在一个服务器上一切运行正常,后来发布到另一个服务器上之后,发现如下错误:
System.InvalidOperationException: DataReader.GetFieldType(5) returned null.数据库中查看发现指定的字段位置为空间坐标类型,应该是发布之后,需要的程序集支持不在而导致的
经历的波折就不多说了,先把解决方案给出:
step1:NuGet package.
中安装SQL Server Spatial Types(#foo)
Microsoft.SqlServer.Typesdependency. Includes the unmanaged dependency SqlServerSpatial.dll in the package 'tools' directory.
其中包含我们所需要的两个程序集:Microsoft.SqlServer.Types
.dll 和 SqlServerSpatial.dll
下面是该安装包中,两个程序集的具体位置
下面的这个程序集是不可被引用的
Step2:引用程序集
将程序集Microsoft.SqlServer.Types .dll添加到项目应用中,并设置属性复制到本地为truestep3:修改web.config
一定要注意程序集的版本信息要与该配置文件设定一致
step4: 发布服务
会发现出现如下错误:Message: UNKNOW_EXCEPTION System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'SqlServerSpatial.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Microsoft.SqlServer.Types.GLNativeMethods.Length(GeoMarshalData g, Double& result) at Microsoft.SqlServer.Types.GLNativeMethods.Length(GeoData g) at Microsoft.SqlServer.Types.SqlGeometry.STLength() --- End of inner exception stack trace --- at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext()
找不到第二个程序集,这也无可厚非,毕竟没有添加到当前项目,发布的时候也不会有该程序集。因为这个程序集是不可添加的。
也没有找到很好的解决方案。
step5: 复制SqlServerSpatial.dll到发布文件的bin目录下
终于看到正常的结果了,简单总结一下,但其中还是做了很多的尝试。之前是安装了上面nuget包中的第一个,并在global中添加对native程序集的访问的代码。可是还是报出错误msvcr100.dll找不到。不管如何按照以上步骤,问题总算得到解决。相关文章推荐
- 【转载】C#多线程编程
- leetcode94 Binary Tree Inorder Traversal
- android开发游记:xml配置图形文件
- 配置本地IIS的证书访问的权限
- Android编程实现自定义系统菜单背景的方法
- 6个经典的经济学小段子
- Android相关的技术博客及文章收集
- jsp内置对象之Application对象
- mongodb基础命令和知识
- git之分支管理策略
- Google Map开发系列(十)——给你的地图加上API提供的默认控件
- Egret)判断移动浏览器
- engine从备份还原时,如果有新版本的engine,必须更新后才能继续恢复
- web前端--知识点,笔记叠加(javascript,jquery,html5+css3.0,ajax)
- web开发菜鸟应该如何向前端大神提问题(一次性把问题描述清楚)
- leetcode93 Restore IP Addresses
- leetcode92 Reverse Linked List II
- Java常用工具类(一)
- Java单例模式探讨
- 每天写一点