SQL Server 2008 Spatial & SharpMapV2

Topics: Data Access, SharpMap v2.0
May 11, 2009 at 11:43 AM


I'm trying the SharpMap.Demo.MapViewer v2 with SQL Server 2008 Express. I get a null exception on line 38 in AsyncResult´1.cs called from line 583 in Layer.cs when adding a connection.It reads the extents from the database correct but I get an exception in the executing thread when the map is about to render.

I've imported and tested different .shp files in the database using AutoCap Map 3D 2010 and SqlSpatial.exe (SqlSpatialTools) without any problems. So my question is: do the SQL Server 2008 dataprovider work in SharpMap? If so, am I doing something wrong? I've updated the sharpmapv2.googlecode.com svn and compiled from the latest source code.


/best regards

Jonas Nilsson

May 11, 2009 at 12:51 PM

Hi Jonas, the Sql 2008 provider works. How did you load the data? Try loading it with the SharpMap.Demo.FormatConverter (build the solution at least twice before running - a macro moves the dlls from the constituent projects to the actual exe root). This gives the option to index the tables as well as creating meta tables which can be used to optimize data access.. hth jd

May 11, 2009 at 12:59 PM

Hi, thanks for the tip! I'll try this tomorrow

I was just debugging the code and dug as deep as to the static method MergeProviderProperties in SpatialDbProviderBase.cs where the exception really originates. Having problem debugging though cause the breakpoint in the method won't bite(!?)


May 12, 2009 at 7:10 AM

I'm sad to say that I haven't had much success. I tried using the FormatConverter from 1 (ShapeFile) to 3 (SLQ Server 2008) with connection string: Server=localhost\SPATIAL;Database=spatialtest;Trusted_Connection=True; and schema db_ddladmin but when the import starts ("Beginning Import") it fails at line 322 in SpatialDbProviderBase.cs with error:

A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":
System.FormatException: 24209: Unexpected end of input. Check that the input data is complete and has not been truncated.
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ReadBytes(Int32 n, ByteOrder byteOrder)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ReadDouble(ByteOrder byteOrder)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ReadNextPoint(ByteOrder byteOrder)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ReadLinearRing(ByteOrder byteOrder, FigureAttributes attributes, UInt32 ringNumber)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ParseWkbPolygonWithoutHeader(ByteOrder byteOrder)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ParseWkb(OpenGisType type)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ParseWkbMultiPolygonWithoutHeader(ByteOrder byteOrder)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.ParseWkb(OpenGisType type)
   vid Microsoft.SqlServer.Types.OpenGisWkbReader.Read(OpenGisType type, Int32 srid)
   vid Microsoft.SqlServer.Types.SqlGeometry.GeometryFromBinary(OpenGisType type, SqlBytes binary, Int32 srid)
   vid Microsoft.SqlServer.Types.SqlGeometry.STGeomFromWKB(SqlBytes wkbGeometry, Int32 srid)
The statement has been terminated.

I tried importing the \NTS\NetTopologySuite.Samples.Shapefiles\b.shp file... when trying to import other .shp-files (shape type: Polygon) i get another error:

The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 7 ("@P4"): Data type 0xE7 has an invalid data length or metadata length.

Any ideas?

/best regards

Jonas Nilsson


May 12, 2009 at 7:41 AM

I just tried converting from ShapeFile to ShapeFile but that din't work. I get at null reference exception at line 1221 in ShapeFileProvider.cs. Tested most of the .shp files in \NTS\NetTopologySuite.Samples.Shapefiles