This project is read-only.

InvalidCastExceptions on all queries using the latest Build

Topics: Developer Forum, User Forum
Sep 2, 2009 at 9:55 PM

Hi, I have been using V1.1 for the last year and have built the newest code and deployed it on my database.  We have getting InvalidCastExceptions on all our queries now.  Below are two examples:

declare @point varbinary(MAX);
declare @MaxSearchDistance decimal(9,7)

SET @MaxSearchDistance = 0.003
SET @point = ST.Point(174.8030, -36.9206, 32740)

SELECT *
FROM NZ_ROADS.ST.RelateQuery('NZ_ROADS.NZ_Regions', 'the_geom', @point, 'within') AS q
INNER JOIN NZ_ROADS.dbo.NZ_Regions AS t ON q.oid = t.oid


SELECT * FROM NZ_ROADS.ST.IsWithinDistanceQuery('NZ_ROADS.NZ_AUCKLAND_ADDRESS', 'the_geom', @point, @MaxSearchDistance) AS q
INNER JOIN NZ_ROADS.dbo.NZ_AUCKLAND_ADDRESS AS f ON q.oid = f.oid order by q.distance

Msg 6522, Level 16, State 1, Line 9
A .NET Framework error occurred during execution of user-defined routine or aggregate "IsWithinDistanceQuery":
System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException:
   at TableValuedFunctions.IsWithinDistanceQueryHandler(SqlDataReader reader, IGeometry geometry, Arguments args)
   at TableValuedFunctions.SpatialQuery.Execute(SqlString table_name, SqlString column_name, SqlBytes ewkbMBR, SqlBytes ewkb, SqlString condition, Arguments args, ReaderHandler handler)
   at TableValuedFunctions.SpatialQuery.Execute(SqlString table_name, SqlString column_name, SqlBytes ewkbMBR, SqlBytes ewkb, Arguments args, ReaderHandler handler)
   at TableValuedFunctions.IsWithinDistanceQuery(SqlString table_name, SqlString column_name, SqlBytes ewkb, SqlDouble distance)

 

Msg 6522, Level 16, State 1, Line 7
A .NET Framework error occurred during execution of user-defined routine or aggregate "RelateQuery":
System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException:
   at TableValuedFunctions.RelateQueryHandler(SqlDataReader reader, IGeometry geometry, Arguments args)
   at TableValuedFunctions.SpatialQuery.Execute(SqlString table_name, SqlString column_name, SqlBytes ewkbMBR, SqlBytes ewkb, SqlString condition, Arguments args, ReaderHandler handler)
   at TableValuedFunctions.SpatialQuery.Execute(SqlString table_name, SqlString column_name, SqlBytes ewkbMBR, Arguments args, ReaderHandler handler)
   at TableValuedFunctions.RelateQuery(SqlString table_name, SqlString column_name, SqlBytes ewkb, SqlString intersectionPattern)

 

This only happens when the queries should be resulting a result else the result is empty.

I compared the difference in RelateQuery.cs between mssqlspatial-24156 and mssqlspatial-48876:
  Line 110
    List<int> oids = new List<int>();  =>    List<Int64> oids = new List<Int64>();
  Line 117:     oids.Add(reader.GetInt32(0));      =>    oids.Add((long)reader.GetValue(0));
  Line 126:     oids.Add(reader.GetInt32(0));      =>    oids.Add((long)reader.GetValue(0));


No change in Line 102-103:

            case "within":
                function = geometry.Within;


So I think nothing wrong in this RelateQuery itself. Implementation of within in GeoAPI might be modified.

We are going to try and figure it out today but any help would be appreciated.


Sep 3, 2009 at 9:43 AM

Hi Blackhawk_andrewr - the data type of the oid column should now be bigint not int as it used to be. hth jd