gpt4 book ai didi

sql-server - DbGeography.PointFromText 24141 : A number is expected at position

转载 作者:行者123 更新时间:2023-12-02 11:08:43 25 4
gpt4 key购买 nike

我有 WCF REST 服务,其中包含以下代码

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

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

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

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

我使用从 SQLServer 安装目录引用的 Microsoft.SqlServer.Types 和 SqlGeography.Point 在代码端处理空间数据。现在我想直接使用 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 Windows NT 6.1 上的 Microsoft Corporation 标准版(内部版本 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);

关于sql-server - DbGeography.PointFromText 24141 : A number is expected at position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15167810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com