微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql-server – DbGeography.PointFromText 24141:预计位置上有一个数字

我有WCF REST服务,其中包含以下代码
var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})",longitude,latitude),DbGeography.DefaultCoordinateSystemId);

单元测试工作正常,但是当我从客户端或HTTP debuder调用代码时,提供纬度和经度的任何值exept 0,它会失败,但异常:

"24141: A number is expected at position X of the input. The input has,XXXXXX."
   at Microsoft.sqlServer.Types.WellKNownTextReader.RecognizeDouble()
   at Microsoft.sqlServer.Types.WellKNownTextReader.ParsePointText(Boolean parseParentheses)
   at Microsoft.sqlServer.Types.WellKNownTextReader.ParseTaggedText(OpenGisType type)
   at Microsoft.sqlServer.Types.WellKNownTextReader.Read(OpenGisType type,Int32 srid)
   at Microsoft.sqlServer.Types.sqlGeography.ParseText(OpenGisType type,sqlChars taggedText,Int32 srid)
   at Microsoft.sqlServer.Types.sqlGeography.GeographyFromText(OpenGisType type,Int32 srid)
   at Microsoft.sqlServer.Types.sqlGeography.STPointFromText(sqlChars pointTaggedText,Int32 srid)

纬度和例如
纬度:37.58336895长:-122.40549454
纬度:37.38931302长:-122.16207476

我使用从sqlServer安装目录和sqlGeography.Point引用的Microsoft.sqlServer.Types来处理代码端的spartial数据.现在我想直接使用EF 5功能,而不使用对Microsoft.sqlServer.Types的引用.它有没有这个参考就失败了.

知道什么是错的吗?

安装了.NET 4.5,sql Server版本是
Microsoft sql Server 2008(SP3) – 10.0.5500.0(Intel X86)2011年9月22日00:28:06版权所有(c)1988-2008 Microsoft Corporation在Windows NT 6.1上的标准版(Build 7601:Service Pack 1)

解决方法

您必须在连接之前使用invariantCulture转换坐标.
String lon = longitude.ToString(CultureInfo.InvariantCulture);
  String lat = latitude.ToString(CultureInfo.InvariantCulture);
  var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})",lon,lat),DbGeography.DefaultCoordinateSystemId);

原文地址:https://www.jb51.cc/mssql/79033.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐