# SQL Server 2008 Error

**URL:** <https://community.thinkgeo.com/t/sql-server-2008-error/2072>\
**Category:** WinForms\
**Created:** [August 27, 2012, 3:53pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072 "2012-08-27T15:53:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/4491bb/32.png) [@Bob3](https://community.thinkgeo.com/u/Bob3)\
**Post date:** [August 27, 2012, 3:53pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/1 "2012-08-27T15:53:21Z")

</div>

I&nbsp;have&nbsp;the&nbsp;following&nbsp;code&nbsp;that&nbsp;is&nbsp;attempting&nbsp;to&nbsp;define&nbsp;a&nbsp;Rectangle&nbsp;in&nbsp;SQL&nbsp;Server&nbsp;2008&nbsp;from&nbsp;a&nbsp;Rectangle&nbsp;I've&nbsp;drawn&nbsp;on&nbsp;the&nbsp;map.

cGeographyInitQuery&nbsp;=&nbsp;string.Format(@"&nbsp;DECLARE&nbsp;@Rectangle&nbsp;geography;&nbsp;SET&nbsp;@Rectangle&nbsp;=&nbsp;geography::STGeomFromText('{0}',&nbsp;4269);",&nbsp;RectangleSelected.GetWellKnownText());

Which&nbsp;formats&nbsp;as&nbsp;follows:

DECLARE&nbsp;@Rectangle&nbsp;geography;

SET&nbsp;@Rectangle&nbsp;=&nbsp;geography::STGeomFromText('POLYGON((&nbsp;-74.933063234375&nbsp;40.5839042578125,&nbsp;-74.3233220234375&nbsp;40.5839042578125,&nbsp;-74.3233220234375&nbsp;40.13895796875,&nbsp;-74.933063234375&nbsp;40.13895796875,&nbsp;-74.933063234375&nbsp;40.5839042578125))',&nbsp;4269);

However&nbsp;when&nbsp;I&nbsp;run&nbsp;the&nbsp;query,&nbsp;I&nbsp;get&nbsp;the&nbsp;following&nbsp;error&nbsp;in&nbsp;SQL&nbsp;Server:

Msg&nbsp;6522,&nbsp;Level&nbsp;16,&nbsp;State&nbsp;1,&nbsp;Line&nbsp;2&nbsp;A&nbsp;.NET&nbsp;Framework&nbsp;error&nbsp;occurred&nbsp;during&nbsp;execution&nbsp;of&nbsp;user-defined&nbsp;routine&nbsp;or&nbsp;aggregate&nbsp;"geography":&nbsp;Microsoft.SqlServer.Types.GLArgumentException:&nbsp;24205:&nbsp;The&nbsp;specified&nbsp;input&nbsp;does&nbsp;not&nbsp;represent&nbsp;a&nbsp;valid&nbsp;geography&nbsp;instance&nbsp;because&nbsp;it&nbsp;exceeds&nbsp;a&nbsp;single&nbsp;hemisphere.&nbsp;Each&nbsp;geography&nbsp;instance&nbsp;must&nbsp;fit&nbsp;inside&nbsp;a&nbsp;single&nbsp;hemisphere.&nbsp;A&nbsp;common&nbsp;reason&nbsp;for&nbsp;this&nbsp;error&nbsp;is&nbsp;that&nbsp;a&nbsp;polygon&nbsp;has&nbsp;the&nbsp;wrong&nbsp;ring&nbsp;orientation.

Since&nbsp;we&nbsp;aren't&nbsp;crossing&nbsp;any&nbsp;hemisphere's&nbsp;it&nbsp;appears&nbsp;as&nbsp;if&nbsp;the&nbsp;"GetWellKnowText()"&nbsp;function&nbsp;is&nbsp;not&nbsp;using&nbsp;the&nbsp;correct&nbsp;ring&nbsp;orientation.&nbsp;How&nbsp;do&nbsp;I&nbsp;correct&nbsp;this?&nbsp;It&nbsp;seems&nbsp;funny&nbsp;that&nbsp;the&nbsp;function&nbsp;wouldn't&nbsp;produce&nbsp;the&nbsp;correctly&nbsp;formated&nbsp;polygon.

Bob

---

<div class="post-metadata">

**Author:** ![Edgar](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@Edgar](https://community.thinkgeo.com/u/Edgar)\
**Post date:** [August 27, 2012, 10:04pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/2 "2012-08-27T22:04:33Z")

</div>

Hi&nbsp;Bob,

I&nbsp;think&nbsp;it&nbsp;should&nbsp;be

DECLARE&nbsp;@Rectangle&nbsp;geometry;

SET&nbsp;@Rectangle&nbsp;=&nbsp;geometry::STGeomFromText('POLYGON((&nbsp;-74.933063234375&nbsp;40.5839042578125,&nbsp;-74.3233220234375&nbsp;40.5839042578125,&nbsp;-74.3233220234375&nbsp;40.13895796875,&nbsp;-74.933063234375&nbsp;40.13895796875,&nbsp;-74.933063234375&nbsp;40.5839042578125))',&nbsp;4269);

Regards,

Edgar

---

<div class="post-metadata">

**Author:** ![Bob3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/4491bb/32.png) [@Bob3](https://community.thinkgeo.com/u/Bob3)\
**Post date:** [August 28, 2012, 11:25am UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/3 "2012-08-28T11:25:59Z")

</div>

Then&nbsp;the&nbsp;coralary&nbsp;question&nbsp;would&nbsp;be…how&nbsp;can&nbsp;you&nbsp;query&nbsp;a&nbsp;geography&nbsp;with&nbsp;a&nbsp;geometry?&nbsp;&nbsp;They&nbsp;wouldn’t&nbsp;be&nbsp;compatible.&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;see,&nbsp;after&nbsp;this&nbsp;defintiion,&nbsp;I’m&nbsp;trying&nbsp;to&nbsp;perform&nbsp;the&nbsp;following&nbsp;in&nbsp;a&nbsp;query,&nbsp;where&nbsp;company.location\_geography&nbsp;is&nbsp;a&nbsp;geography&nbsp;column.&nbsp;  
&nbsp;&nbsp;  
&nbsp;@Rectangle.STIntersects(company.location\_geography)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Your&nbsp;thoughts?&nbsp;  
&nbsp;&nbsp;  
&nbsp;bob

---

<div class="post-metadata">

**Author:** ![Bob3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/4491bb/32.png) [@Bob3](https://community.thinkgeo.com/u/Bob3)\
**Post date:** [August 28, 2012, 2:53pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/4 "2012-08-28T14:53:48Z")

</div>

So&nbsp;I&nbsp;took&nbsp;the&nbsp;above&nbsp;original&nbsp;Rectangle&nbsp;and&nbsp;reversed&nbsp;all&nbsp;the&nbsp;points&nbsp;and&nbsp;Geography&nbsp;worked&nbsp;as&nbsp;well&nbsp;as&nbsp;the&nbsp;Geometry!!&nbsp;&nbsp;So&nbsp;why&nbsp;doesn’t&nbsp;the&nbsp;function&nbsp;return&nbsp;the&nbsp;points&nbsp;in&nbsp;the&nbsp;right&nbsp;order?&nbsp;  
&nbsp;&nbsp;  
&nbsp;This&nbsp;seems&nbsp;like&nbsp;a&nbsp;bug&nbsp;to&nbsp;me.&nbsp;  
&nbsp;&nbsp;  
&nbsp;bob

---

<div class="post-metadata">

**Author:** ![Edgar](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@Edgar](https://community.thinkgeo.com/u/Edgar)\
**Post date:** [August 28, 2012, 8:08pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/5 "2012-08-28T20:08:34Z")

</div>

Bob,&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;seems&nbsp;that&nbsp;using&nbsp;geography&nbsp;is&nbsp;more&nbsp;strict&nbsp;than&nbsp;using&nbsp;geometry,&nbsp;the&nbsp;polygon’s&nbsp;outer&nbsp;ring&nbsp;must&nbsp;be&nbsp;counterclockwise,&nbsp;we’ve&nbsp;made&nbsp;the&nbsp;changes,&nbsp;please&nbsp;get&nbsp;6.0.108.0&nbsp;or&nbsp;6.0.0.108&nbsp;and&nbsp;have&nbsp;a&nbsp;try.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Edgar

---

<div class="post-metadata">

**Author:** ![Bob3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/4491bb/32.png) [@Bob3](https://community.thinkgeo.com/u/Bob3)\
**Post date:** [August 29, 2012, 10:09am UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/6 "2012-08-29T10:09:33Z")

</div>

That&nbsp;may&nbsp;be&nbsp;a&nbsp;problem.&nbsp;&nbsp;I’m&nbsp;currently&nbsp;in&nbsp;the&nbsp;60&nbsp;day&nbsp;evaluation&nbsp;period,&nbsp;and&nbsp;the&nbsp;demo&nbsp;link&nbsp;indicates&nbsp;version&nbsp;6.0.0.0.&nbsp;&nbsp;Has&nbsp;the&nbsp;Eval&nbsp;been&nbsp;updated&nbsp;for&nbsp;these&nbsp;corrections?&nbsp;  
&nbsp;&nbsp;  
&nbsp;bob

---

<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:** [August 29, 2012, 5:42pm UTC](https://community.thinkgeo.com/t/sql-server-2008-error/2072/7 "2012-08-29T17:42:19Z")

</div>

Hello&nbsp;Bob,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Both&nbsp;the&nbsp;evaluation&nbsp;and&nbsp;full&nbsp;version&nbsp;have&nbsp;made&nbsp;the&nbsp;changes,&nbsp;you&nbsp;can&nbsp;get&nbsp;the&nbsp;evaluation&nbsp;6.0.108.0&nbsp;or&nbsp;6.0.0.108&nbsp;and&nbsp;have&nbsp;a&nbsp;try.&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;can&nbsp;find&nbsp;the&nbsp;download&nbsp;link&nbsp;in&nbsp;[helpdesk.thinkgeo.com](http://helpdesk.thinkgeo.com).&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary
