This project has moved and is read-only. For the latest updates, please go here.

SQL Server 2008 Provider

Topics: SharpMap v0.9 / v1.x
Aug 3, 2011 at 4:28 PM


I tried loading large data on VectorLayer using ShapeFile and SQLServer2008 providers (the same data was tested).

ShapeFile provider was much faster than SQLServer2008.

Also if I set SRID to VectorLayer with SQLServer2008 datasource, no data is displayed. Is this expected behavior ?

Here is the code used to load SQL2008

VectorLayer layer = new VectorLayer("largeData");
SqlServer2008 sql2008 = new SharpMap.Data.Providers.SqlServer2008(connStr, tableName, geometryColumn, oidColumn);
            sql2008 .DefinitionQuery = query;
layer.DataSource = sql2008 ;



Aug 3, 2011 at 7:22 PM

hello carjona, in one of the latest check-ins the SqlServer2008 provider got an additional constructur parameter (useSpatialIndexExtentAsExtent), that switched the way how the layers extent was queried.

It should be considerably faster setting it to true (default is false).

Hth FObermaier

Aug 3, 2011 at 7:41 PM
Edited Aug 3, 2011 at 11:49 PM

Hi Carjona, "SELECT geomColumn.STSrid from geometrytable" must match the provided SRID. 

You can update the table with 

UPDATE geometryTable SET geometryColumn.STSrid = 4326

for example 

hth jd


EDIT: For performance make sure your table is appropriately spatially indexed..

Aug 3, 2011 at 8:05 PM

seems like I only read half the message :)

Aug 5, 2011 at 10:28 PM

Hello, thank you both !

JD: After setting SRID and Spatial Index performance improved very much.

FObermaier: I got an error when searching on features. GetFeature function wasnt getting any data. It worked after changing DataSet instead of FeatureDataSet.

//FeatureDataSet ds = new FeatureDataSet();
System.Data.DataSet ds = new System.Data.DataSet();
adapter.Fill(ds, Table);   
Also, on GetExtents function, if _UseSpatialIndexExtentAsExtent, the order of bounding x, y is wrong. It should be like this
//bx = new BoundingBox(Convert.ToDouble(dr["bounding_box_xmin"]),
//    Convert.ToDouble(dr["bounding_box_xmax"]),
//    Convert.ToDouble(dr["bounding_box_ymin"]),
//    Convert.ToDouble(dr["bounding_box_ymax"]));
bx = new BoundingBox(Convert.ToDouble(dr["bounding_box_xmin"]),
Thank you again for your help !
Aug 8, 2011 at 7:54 AM

Thanks for pointing that out carjona, I've checked that fix now.