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) 纬度和例如 我使用从SQLServer安装目录和SqlGeography.Point引用的Microsoft.SqlServer.Types来处理代码端的spartial数据.现在我想直接使用EF 5功能,而不使用对Microsoft.SqlServer.Types的引用.它有没有这个参考就失败了. 知道什么是错的吗? 安装了.NET 4.5,SQL Server版本是 解决方法您必须在连接之前使用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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |