我正在使用 Visual Studio 2013 和 SQL Server 2012 在 C# 中进行开发。我已经能够使用 T-SQL 将多边形存储在地理列中,并且我没有尝试在代码中使用 SqlGeography 类来检索数据。
当我尝试:
SqlGeography polyB = (SqlGeography)dr["extent"]; // stored in OGC Well Known Binary format
从我收到消息的数据库中检索多边形:
GeoLib.dll 中出现“System.InvalidCastException”类型的未处理异常
附加信息:[A]Microsoft.SqlServer.Types.SqlGeography 不能转换为 [B]Microsoft.SqlServer.Types.SqlGeography。类型 A 源自 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' 在位置 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0 的上下文 'Default' 中.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'。
类型 B 源自 'Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' 在位置'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0 的上下文'Default'中.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll'。
我怀疑 SQL Server 和 Visual Studio 之间的版本不兼容,如不同的版本号所示。有没有人遇到过这个?也许我需要安装 SQL Server 2014?任何想法表示赞赏!