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

Getting spatial data from MSSQL problem

Topics: Data Access, Algorithms
Jul 4, 2007 at 8:52 AM
I am very new in GIS and I have got a problem with getting spatial data from MSSQL, I am using the newest version of SharpMap.dll (compiled from source code), can anyone help me with this problem ? Do I make something wrong with this code ?!

the code:

string ConnStr = "Data Source=KULKA;Initial Catalog=spatial_geo4;Integrated Security=True";

SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("World");
SharpMap.Data.Providers.MsSql dataSource = new SharpMap.Data.Providers.MsSql(ConnStr, "World", "the_geom", "oid");
// In debug mode I can see that dataSource Columns throws following exception: The method or operation is not implemented. at //SharpMap.Data.Providers.MsSql.get_Columns()
dataSource.DefinitionQuery = String.Empty;

layer.DataSource = dataSource;
layer.Style.Line = new Pen(Color.White);
layer.Style.Outline = new Pen(Color.Brown);
layer.Style.EnableOutline = true;
layer.Style.Fill = Brushes.Green;
layer.Enabled = true;

map = new SharpMap.Map(this.pictureBox1.Size);

//map.ZoomToExtents(); this line throws an exception !!!

map.GetMap().Save("World.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
this.pictureBox1.Image = map.GetMap();
catch (Exception ex)

The exception thrown by map.ZoomToExtents()
"Specified cast is not valid."
at SharpMap.Data.Providers.MsSql.GetExtents()
at SharpMap.Layers.VectorLayer.get_Envelope()
at SharpMap.Map.GetExtents()
at SharpMap.Map.ZoomToExtents()
at Shape2Pgsql.Form1.button1_Click(Object sender, EventArgs e) in D:\Documents and Settings\Maciej\Pulpit\GIS\Shape2Pgsq\Shape2Pgsql\Form1.cs:line 338

Maciej Wrzesniowski
Jul 4, 2007 at 3:11 PM

I have changed Provider to MsSqlSpatial and the column names (again) in data base from 'EnvelopeMinX' to 'thegeomEnvelopeMinX'

SharpMap.Data.Providers.MsSqlSpatial dataSource = new SharpMap.Data.Providers.MsSqlSpatial(ConnStr, "World", "the_geom", "oid");

Maciej W.

Jul 4, 2007 at 3:13 PM
Jul 8, 2007 at 11:50 AM
When trying the above, i get a compilation error stating that type 'MsSqlSpatiol' does not exist. Also tried the latest RC 0.9.2241. But still nothing.