# SQL SPatial Connection

**URL:** <https://community.thinkgeo.com/t/sql-spatial-connection/6961>\
**Category:** Silverlight\
**Created:** [September 18, 2011, 6:49am UTC](https://community.thinkgeo.com/t/sql-spatial-connection/6961 "2011-09-18T06:49:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wael](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/w/b9e5f3/32.png) [@wael](https://community.thinkgeo.com/u/wael)\
**Post date:** [September 18, 2011, 6:49am UTC](https://community.thinkgeo.com/t/sql-spatial-connection/6961/1 "2011-09-18T06:49:01Z")

</div>

&nbsp;Please&nbsp;help&nbsp;me&nbsp;adding&nbsp;SQL&nbsp;Spatial&nbsp;Layer&nbsp;to&nbsp;Map1&nbsp;in&nbsp;my&nbsp;silverlight&nbsp;applicatin&nbsp;

DB&nbsp;details:

UNAME:&nbsp;wael&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PW:&nbsp;password&nbsp;&nbsp;&nbsp;DB&nbsp;Name:Incidents&nbsp;&nbsp;&nbsp;Table&nbsp;Name:&nbsp;SQLSpatial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;

I&nbsp;would&nbsp;be&nbsp;thankfull&nbsp;if&nbsp;some&nbsp;guide&nbsp;me&nbsp;to&nbsp;right&nbsp;way

&nbsp;

Regards

Wael

---

<div class="post-metadata">

**Author:** ![wael](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/w/b9e5f3/32.png) [@wael](https://community.thinkgeo.com/u/wael)\
**Post date:** [September 18, 2011, 7:10am UTC](https://community.thinkgeo.com/t/sql-spatial-connection/6961/2 "2011-09-18T07:10:13Z")

</div>

This&nbsp;is&nbsp;my&nbsp;XAM&nbsp;Code&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;using&nbsp;System;&nbsp;  
&nbsp;using&nbsp;System.Collections.Generic;&nbsp;  
&nbsp;using&nbsp;System.Linq;&nbsp;  
&nbsp;using&nbsp;[System.Net](http://System.Net);&nbsp;  
&nbsp;using&nbsp;System.Windows;&nbsp;  
&nbsp;using&nbsp;System.Windows.Controls;&nbsp;  
&nbsp;using&nbsp;System.Windows.Documents;&nbsp;  
&nbsp;using&nbsp;System.Windows.Input;&nbsp;  
&nbsp;using&nbsp;System.Windows.Media;&nbsp;  
&nbsp;using&nbsp;System.Windows.Media.Animation;&nbsp;  
&nbsp;using&nbsp;System.Windows.Shapes;&nbsp;  
&nbsp;using&nbsp;ThinkGeo.MapSuite.SilverlightEdition;&nbsp;  
&nbsp;using&nbsp;ThinkGeo.MapSuite.SilverlightCore;&nbsp;  
&nbsp;&nbsp;  
&nbsp;namespace&nbsp;Samples6683&nbsp;  
&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;partial&nbsp;class&nbsp;MainPage&nbsp;:&nbsp;UserControl&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;MainPage()&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitializeComponent();&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;LayoutRoot\_Loaded(object&nbsp;sender,&nbsp;RoutedEventArgs&nbsp;e)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.MapUnit&nbsp;=&nbsp;GeographyUnit.Meter;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.Background&nbsp;=&nbsp;new&nbsp;SolidColorBrush(Color.FromArgb(255,&nbsp;156,&nbsp;187,&nbsp;216));&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.CurrentExtent&nbsp;=&nbsp;new&nbsp;RectangleShape(-13939426.6371,&nbsp;6701997.4056,&nbsp;-7812401.86,&nbsp;2626987.386962);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerLayerOverlay&nbsp;serverLayerOverlay&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithGoogleRoadMap",&nbsp;"SilverlightMapConnector1");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.Overlays.Add(serverLayerOverlay);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ServerLayerOverlay&nbsp;serverLayerOverlay1&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithVirtualEarthMap",&nbsp;"SilverlightMapConnector1");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[//Map1.Overlays.Add](https://Map1.Overlays.Add)(serverLayerOverlay1);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerLayerOverlay&nbsp;serverLayerOverlay2&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithMsSql",&nbsp;"SilverlightMapConnector1");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.Overlays.Add(serverLayerOverlay2);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.Refresh();&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;}&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;This&nbsp;is&nbsp;my&nbsp;ASP&nbsp;net&nbsp;code&nbsp;  
&nbsp;&nbsp;  
&nbsp;using&nbsp;System;&nbsp;  
&nbsp;using&nbsp;System.Collections.Generic;&nbsp;  
&nbsp;using&nbsp;System.Linq;&nbsp;  
&nbsp;using&nbsp;System.Web;&nbsp;  
&nbsp;using&nbsp;System.Web.UI;&nbsp;  
&nbsp;using&nbsp;System.Web.UI.WebControls;&nbsp;  
&nbsp;using&nbsp;ThinkGeo.MapSuite.Core;&nbsp;  
&nbsp;using&nbsp;ThinkGeo.MapSuite.SilverlightEdition;&nbsp;  
&nbsp;using&nbsp;System.Drawing;&nbsp;  
&nbsp;using&nbsp;System.Globalization;&nbsp;  
&nbsp;&nbsp;  
&nbsp;namespace&nbsp;Samples6683.Web&nbsp;  
&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;partial&nbsp;class&nbsp;\_Default&nbsp;:&nbsp;System.Web.UI.Page&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;void&nbsp;Page\_Load(object&nbsp;sender,&nbsp;EventArgs&nbsp;e)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!Page.IsPostBack)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GoogleMapsLayer&nbsp;googleRoadLayer&nbsp;=&nbsp;new&nbsp;GoogleMapsLayer();&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;googleRoadLayer.MapType&nbsp;=&nbsp;GoogleMapsMapType.RoadMap;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerLayerOverlay&nbsp;layerWithGoogelRoadMapOverlay&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithGoogleRoadMap");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layerWithGoogelRoadMapOverlay.Layers.Add(googleRoadLayer);&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SilverlightMapConnector1.ServerLayerOverlays.Add(layerWithGoogelRoadMapOverlay);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;////&nbsp;Please&nbsp;set&nbsp;your&nbsp;own&nbsp;information&nbsp;about&nbsp;those&nbsp;parameters&nbsp;below.&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//string&nbsp;accountId&nbsp;=&nbsp;"wael";&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//string&nbsp;password&nbsp;=&nbsp;"v2500";&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//string&nbsp;clientIpAddress&nbsp;=&nbsp;"localhost";&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//string&nbsp;cacheDirectory&nbsp;=&nbsp;@"c:\temp&#34;;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//VirtualEarthLayer&nbsp;worldLayer&nbsp;=&nbsp;new&nbsp;VirtualEarthLayer(accountId,&nbsp;password,&nbsp;clientIpAddress,&nbsp;cacheDirectory);&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ServerLayerOverlay&nbsp;layerWithVirtualEarthOverlay&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithVirtualEarthMap");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[//SilverlightMapConnector1.ServerLayerOverlays.Add](https://SilverlightMapConnector1.ServerLayerOverlays.Add)(layerWithVirtualEarthOverlay);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Please&nbsp;set&nbsp;your&nbsp;own&nbsp;information&nbsp;about&nbsp;those&nbsp;parameters&nbsp;below.&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;connectString&nbsp;=&nbsp;"Data&nbsp;Source=10.42.128.158,1041;Initial&nbsp;Catalog=Incidents;Persist&nbsp;Security&nbsp;Info=True;User&nbsp;ID=wael;Password=v2500";&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsSql2008FeatureLayer&nbsp;sql2008Layer&nbsp;=&nbsp;new&nbsp;MsSql2008FeatureLayer(connectString,&nbsp;"SqlSpatial",&nbsp;"gid");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle&nbsp;=&nbsp;AreaStyles.Country1;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel&nbsp;=&nbsp;ApplyUntilZoomLevel.Level20;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerLayerOverlay&nbsp;layerWithMsSql2008FeatureOverlay&nbsp;=&nbsp;new&nbsp;ServerLayerOverlay("NativeServerWithMsSql");&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layerWithMsSql2008FeatureOverlay.Layers.Add(sql2008Layer);&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SilverlightMapConnector1.ServerLayerOverlays.Add(layerWithMsSql2008FeatureOverlay);&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;  
&nbsp;}&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;neither&nbsp;the&nbsp;google&nbsp;maps&nbsp;nor&nbsp;the&nbsp;sql&nbsp;spatial&nbsp;can&nbsp;be&nbsp;seen&nbsp;on&nbsp;the&nbsp;map.&nbsp;also&nbsp;note&nbsp;that&nbsp;my&nbsp;area&nbsp;of&nbsp;interest&nbsp;are&nbsp;in&nbsp;the&nbsp;middle&nbsp;east&nbsp;&nbsp;  
&nbsp;&nbsp;&&nbsp;I&nbsp;dont&nbsp;know&nbsp;how&nbsp;to&nbsp;adjust&nbsp;the&nbsp;focus&nbsp;extent&nbsp;of&nbsp;the&nbsp;map&nbsp;to&nbsp;get&nbsp;my&nbsp;area&nbsp;of&nbsp;interest&nbsp;(I&nbsp;can&nbsp;not&nbsp;predict&nbsp;the&nbsp;numbers)&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;thank&nbsp;you

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [September 19, 2011, 3:19pm UTC](https://community.thinkgeo.com/t/sql-spatial-connection/6961/3 "2011-09-19T15:19:02Z")

</div>

Dear&nbsp;wael,&nbsp;  
  
  
  
Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;sample&nbsp;code,&nbsp;I&nbsp;have&nbsp;checked&nbsp;it&nbsp;and&nbsp;tried,&nbsp;I&nbsp;think&nbsp;the&nbsp;code&nbsp;didn't&nbsp;have&nbsp;problems,&nbsp;and&nbsp;I&nbsp;can&nbsp;show&nbsp;the&nbsp;GoogleMap(sorry&nbsp;I&nbsp;can't&nbsp;test&nbsp;your&nbsp;sql),&nbsp;maybe&nbsp;the&nbsp;problem&nbsp;is&nbsp;in&nbsp;the&nbsp;project,&nbsp;so&nbsp;I&nbsp;remake&nbsp;a&nbsp;sample&nbsp;using&nbsp;your&nbsp;code&nbsp;and&nbsp;reference&nbsp;right&nbsp;dlls,&nbsp;please&nbsp;download&nbsp;it&nbsp;have&nbsp;an&nbsp;other&nbsp;try.&nbsp;  
  
  
  
Also&nbsp;I&nbsp;have&nbsp;changed&nbsp;the&nbsp;extent&nbsp;to&nbsp;the&nbsp;Middle&nbsp;East.&nbsp;I&nbsp;hope&nbsp;it&nbsp;can&nbsp;help&nbsp;you.&nbsp;  
  
  
  
Regards,&nbsp;  
  
  
  
Gary

[SamplesUsingGoogle&Sql.zip](https://community.thinkgeo.com/uploads/default/original/2X/c/c1fa2d29f99276055608a1ff887f1e4af4ba7a04.zip) (15.9 KB)
