# BuildIndex error

**URL:** <https://community.thinkgeo.com/t/buildindex-error/1329>\
**Category:** WinForms\
**Created:** [July 6, 2010, 8:10am UTC](https://community.thinkgeo.com/t/buildindex-error/1329 "2010-07-06T08:10:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [July 6, 2010, 8:10am UTC](https://community.thinkgeo.com/t/buildindex-error/1329/1 "2010-07-06T08:10:52Z")

</div>

I&nbsp;am&nbsp;using&nbsp;MsSql2008FeatureLayer&nbsp;to&nbsp;display&nbsp;spatial&nbsp;data&nbsp;and&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;insure&nbsp;that&nbsp;I&nbsp;have&nbsp;spatial&nbsp;indices&nbsp;on&nbsp;all&nbsp;of&nbsp;my&nbsp;geometry&nbsp;tables.&nbsp;&nbsp;I&nbsp;get&nbsp;an&nbsp;error&nbsp;on&nbsp;one&nbsp;table.&nbsp;&nbsp;It&nbsp;has&nbsp;a&nbsp;single&nbsp;point&nbsp;type&nbsp;feature&nbsp;in&nbsp;it.&nbsp;&nbsp;I&nbsp;have&nbsp;checked&nbsp;that&nbsp;the&nbsp;feature&nbsp;is&nbsp;valid&nbsp;(STIsValid).&nbsp;&nbsp;I&nbsp;get&nbsp;this&nbsp;error:

Unable&nbsp;to&nbsp;cast&nbsp;object&nbsp;of&nbsp;type&nbsp;'System.DBNull'&nbsp;to&nbsp;type&nbsp;'System.Byte[]'

The&nbsp;Location&nbsp;field&nbsp;is&nbsp;not&nbsp;null.&nbsp;&nbsp;I&nbsp;realize&nbsp;there&nbsp;is&nbsp;not&nbsp;much&nbsp;need&nbsp;for&nbsp;a&nbsp;spatial&nbsp;index&nbsp;on&nbsp;a&nbsp;table&nbsp;with&nbsp;only&nbsp;one&nbsp;record.&nbsp;&nbsp;Is&nbsp;this&nbsp;not&nbsp;allowed?

&nbsp;

Charles

---

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [July 6, 2010, 8:12am UTC](https://community.thinkgeo.com/t/buildindex-error/1329/2 "2010-07-06T08:12:25Z")

</div>

This&nbsp;also&nbsp;happens&nbsp;with&nbsp;a&nbsp;table&nbsp;that&nbsp;contains&nbsp;a&nbsp;single&nbsp;line&nbsp;string.

Charles

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 7, 2010, 2:00am UTC](https://community.thinkgeo.com/t/buildindex-error/1329/3 "2010-07-07T02:00:32Z")

</div>

Charles,

Thanks&nbsp;for&nbsp;your&nbsp;post.  
&nbsp;  
I&nbsp;agree&nbsp;with&nbsp;you&nbsp;that&nbsp;this&nbsp;problem&nbsp;will&nbsp;be&nbsp;happening&nbsp;when&nbsp;calling&nbsp;the&nbsp;GetBoundingBox&nbsp;for&nbsp;an&nbsp;MsSqlFeatureLayer&nbsp;in&nbsp;which&nbsp;only&nbsp;one&nbsp;feature&nbsp;exists.&nbsp;Following&nbsp;code&nbsp;shows&nbsp;a&nbsp;way&nbsp;to&nbsp;go&nbsp;around&nbsp;this&nbsp;problem&nbsp;now;&nbsp;we&nbsp;will&nbsp;try&nbsp;to&nbsp;fix&nbsp;it&nbsp;in&nbsp;future&nbsp;versions.  
&nbsp;  
`        private void DisplayMap_Load(object sender, EventArgs e)        {            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;             winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);             string connectString = "Data Source=192.168.0.212;Initial Catalog= **;Persist Security Info=True;User ID=sa;Password=****";            MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "cntry02", "ID");            sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;            sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;             LayerOverlay staticOverlay = new LayerOverlay();            staticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);            winformsMap1.Overlays.Add(staticOverlay);             sql2008Layer.Open();            winformsMap1.CurrentExtent = GetSqlLayerBoundingBox(sql2008Layer);//sql2008Layer.GetBoundingBox();            sql2008Layer.Close();             winformsMap1.Refresh();        }         private RectangleShape GetSqlLayerBoundingBox(MsSql2008FeatureLayer sql2008Layer)        {            RectangleShape returnBoundingBox = new RectangleShape();            try            {                sql2008Layer.Open();                 int count = sql2008Layer.QueryTools.GetCount();                if (count == 1)                {                    returnBoundingBox = sql2008Layer.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns)[0].GetBoundingBox();                }                else                {                    returnBoundingBox = sql2008Layer.GetBoundingBox();                }            }            finally            {                sql2008Layer.Close();            }             return returnBoundingBox;        }`  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale
