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);

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...