ThinkGeo.com    |     Documentation    |     Premium Support

MsSQL2008FeatureLayer exception

Good Evening! I added a few layers to my map that all rely on different sql server tables. I now am getting a NullReferencePointer on my first map.Refresh(). I'm not on the latest version, didn't have time to make changes before demo. These are newly created tables I'm working with. The geography column is a computed column (meaning I have Lat and Long as floats and a column that combines these into a point.) When I get the text version of the computed points, they all look fine. All of my layers are showing >1 feature after initialization. Anything else I should say?


Any idea what might be causing the null reference exception? Does it not like the computed column, anyone know? Any other thoughts on things to try?


(This is another time when a more specific error message/failing earlier would be helpful, I'm guessing.)


Thank you!


Kimberly



Kimberly,


Thanks for your post. 


Up to now, we are not very clear with your problems. Following is our test codes; Can you let us know which version you are using (the latest one is 3.0.307RC desktop) and can you paste your code out to show us what is going on?



   // Load 2 layers from 2 different tables.
  private void Form1_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

            winformsMap1.CurrentExtent = new RectangleShape(-126.4, 48.8, -67.0, 19.0);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "States", "recid");
            sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            sql2008Layer.Srid = 4326;

            MsSql2008FeatureLayer sql2008LineLayer = new MsSql2008FeatureLayer(connectString, "Austinstreets", "recid");
            sql2008LineLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1;
            sql2008LineLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            sql2008LineLayer.Srid = 4326;

            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);
            staticOverlay.Layers.Add("Sql2008LineLayer", sql2008LineLayer);
            winformsMap1.Overlays.Add(staticOverlay);

            winformsMap1.Refresh();
        }

  // Generate another table in the button-click event. We verify that this operation is successful and can be displayed in the Map.
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            MsSql2008FeatureLayer sql2008LineLayer = new MsSql2008FeatureLayer(connectString, "TempPoint", "recid");
            sql2008LineLayer.Srid = 4326;
            sql2008LineLayer.Open();
            TransactionResult result = new TransactionResult();
            sql2008LineLayer.EditTools.BeginTransaction();
            Random random = new Random();
            for (int i = 0; i < 1000; i++)
            {
                double randomX = random.NextDouble() * 360;
                double randomY = random.NextDouble() * 180;
                float x = (float)(randomX - 180);
                float y = (float)(randomY - 90);
                
                Feature newFeature = new Feature(x, y, (i + 1).ToString(), new string[]{"X:" + x.ToString(), "Y:" + y.ToString(), "RECID:" + (i+1).ToString()});
                sql2008LineLayer.EditTools.Add(newFeature);
            }
            result = sql2008LineLayer.EditTools.CommitTransaction();
            MessageBox.Show(string.Format("Finished with {0} succeed and {1} failed.", result.TotalSuccessCount.ToString(), result.TotalFailureCount.ToString()));
        }

Any more questions just let me know.


Thanks.


Yale