【问题标题】:SqlGeometry / DbGeometry Isvalid exception when hosting on Azure Web Role在 Azure Web 角色上托管时出现 SqlGeometry / DbGeometry Isvalid 异常
【发布时间】:2013-07-31 17:48:29
【问题描述】:

我正在尝试创建一个DbGeometry 类型的多边形。它在我的本地计算机上运行良好,但在 Azure Web 角色上托管我的网站时,我在返回语句中出现错误。

代码:

string polygon = “POLYGON ((-30.3637216 30.7124139,-30.3632216 30.7124139,-30.3632216 30.7129139,-30.3637216 30.7129139,-30.3637216 30.7124139))”;

return DbGeometry.FromText(polygon, 4326);

例外:

Exception has been thrown by the target of an invocation.


at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.Data.SqlClient.SqlSpatialServices.GeometryFromText(String geometryText)

   at Library.Modules.FindMyWay.SpatialFunctions.GetDefaultBox(Decimal latitude, Decimal longitude)

   at Library.Stop.ImportStops(String userName, IEnumerable`1 stops, Int32 companyId) Inner Exception:    at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoMarshalData g, Boolean& result)

   at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoData g)

   at Microsoft.SqlServer.Types.SqlGeometry.IsValidExpensive()

   at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid)

   at Microsoft.SqlServer.Types.SqlGeometry.Parse(SqlString s)

你知道为什么这个多边形无效吗?

【问题讨论】:

  • 我没有答案,只是想评论一下,我们看到了一个类似的问题,即 SqlGeometry 可以在所有上下文中工作,除非作为 azure web 角色运行。它在本地工作。它作为一个天蓝色的网站工作。只是不作为一个网络。

标签: c# entity-framework-5 .net-4.5 azure-sql-database azure-web-roles


【解决方案1】:

好的,我通过将 SqlGeometry 转换为 DbGeometry 以迂回的方式解决了这个问题:

is there something like dbgeometry makevalid in .net 4.5

SqlGeometry geom = SqlGeometry.STPolyFromText(new SqlChars(new SqlString(polygon)), 4326);
                 return DbGeometry.FromBinary(geom.STAsBinary().Buffer);

这段代码产生了异常:

Unable to load DLL 'SqlServerSpatial.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

修复:

Unable to load DLL 'SqlServerSpatial.dll'

64 位 dll 导致了这个异常:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

所以我必须将 32 位 dll 添加到项目中才能使用 Azure。

结果:现在很好,但我仍然不确定为什么 DbGeometry 无法在 Azure 上运行,也不确定为什么 64 位 dll 也无法在 Azure 上运行。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。我的解决方法是将以下 Dll 放入文件夹 C:/windows/System32:

    SqlServerSpatial.dll SqlServerSpatial110.dll

    实体框架根据以下来源使用这些 dll: https://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/

    【讨论】:

      猜你喜欢
      • 2015-01-27
      • 1970-01-01
      • 2012-05-12
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多