Hello, I'm need some help regarding of my problem about using MsSql2008FeatureLayer.
I'm using SQL Server 2008 R2 Express with Visual Studio 2010 and MapSuite Desktop 6.0 Trial. I have converted example Countries02.shp using Shape2Sql program from (sharpgis.net/page/sql-server-2008-spatial-tools.aspx). The file is successfully converted into my database: SpatialDatabase, table name: Countries02.
Then I tried to load and view it with MsSql2008FeatureLayer. Since I've been using ShapeFileFeatureLayer with Countries02.shp without any problem, I assume the process would be the same for the MsSql2008FeatureLayer. First there was an error saying that some of the records need to be valid first. I've run into some sites state that I need to run a spesific SQL query to make the invalid records into valid records. I was using sql query
update Countries02 set geom = geom.MakeValid() where geom.STIsValid() = 0
the result there were 3 row(s) are affected.
After that I tried to show them with Sql Spatial Query Visualizer (included from the link above) and it shows correctly. But then when I load with MsSql2008FeatureLayer, the layer won't appear. There are no error with program, but the layer just doesn't appear at all. I've tried to change inside the MsSql2008FeatureLayer constructor the RecID (original from the shp file) with ID (generated new with Shape2Sql) but it doesn't work either.
Here's my code
string connectString = @"Data Source=<my_pc_database>;Initial Catalog=SpatialDatabase;Integrated Security=True;User ID=<my_id>;Password=<my_password>";
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
MsSql2008FeatureLayer worldShapeLayer = new MsSql2008FeatureLayer(connectString, "Countries02", "RecID");
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
worldShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;
worldShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.StateBorder1;
worldShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
worldShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldShapeLayer", worldShapeLayer);
winformsMap1.CurrentExtent = this.GetFullExtent(staticOverlay.Layers);
winformsMap1.Overlays.Add("WorldOverlay", staticOverlay);
winformsMap1.Refresh();
The function GetFullExtent() is taken from another example from this forum, but I think that's not the problem since it worked perfectly with ShapeFileFeatureLayer. Are there anything wrong with my code or something did I miss to add? Thank you for your attention.