DbGeography.PointFromText 24141: expected number in position

I have a WCF REST service that contains the following code

var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})", longitude, latitude), DbGeography.DefaultCoordinateSystemId); 

Unit test works fine , but when I call this code from a client or HTTP debugger, providing any latitude and longitude values ​​except zeros, it does not work with the exception:

 "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, SqlChars taggedText, Int32 srid) at Microsoft.SqlServer.Types.SqlGeography.STPointFromText(SqlChars pointTaggedText, Int32 srid) 

latitude and duration for example
lat: 37.58336895 long: -122.40549454
lat: 37.38931302 long: -122.16207476

I used Microsoft.SqlServer.Types, which are referenced in the SQLServer and SqlGeography.Point installation directory to work with third-party data on the code side. Now I want to use the EF 5 functions directly, without using the link to Microsoft.SqlServer.Types. He cannot cope with this link without it.

Any idea what's wrong?

Installed .NET 4.5, SQL Server version Microsoft SQL Server 2008 (SP3) - 10.0.5500.0 (Intel X86) 09/22/2011 00:28:06 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition for Windows NT 6.1 (build 7601: Service Pack 1)

+8
sql-server entity-framework-5 spatial
source share
1 answer

You need to transform the coordinates using the Culture invariant before concatenating.

  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); 
+12
source share

All Articles