2

I just finished importing census block shape files into Microsoft SQL Server 2012 and am now having issues when trying to use some of the geography features (STContains, STWithin, UnionAggregate, etc) on the data I've brought in. I checked the .prj file before importing my .shp files and I'm sure it is geogrpahy and not geometry type.

This is the example I've been trying, just to test it out (which comes straight from the MSDN website):

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::Parse('CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (-122.200928    47.454094, -122.810669 47.00648, -122.942505 46.687131, -121.14624 45.786679, -119.119263  46.183634), (-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.200928 47.454094)))');
SET @h = geography::Parse('POINT(-121.703796 46.893985)');

select @g.stcontains(@h)

This is the error I receive:

Msg 6506, Level 16, State 10, Line 6
Could not find method 'stcontains' for type 'Microsoft.SqlServer.Types.SqlGeography' in  assembly 'Microsoft.SqlServer.Types'

I have done some research on the subject and it appears as though I need to install some sort of add on feature. I checked my C: folder because I saw a recommendation to install it via Program Files/Microsoft SQL Server/100/SDK/Assemblies/Microsoft.SqlServer.Types.dll but got stumped because I couldn't find an 'Assemblies' folder. I also saw a recommendation to download the Microsoft SQL Server 2012 feature pack (http://www.microsoft.com/en-us/download/details.aspx?id=29065) but I wasn't sure what exactly I needed, if that was even the right spot to look.

Any help that you may offer would be greatly appreciated. Thanks in advance.

  • I'm having the same problem. Anyone have the answer for this? Or can anyone file a bug report with Microsoft for this? We are running SQL Server 2014, and database compatibility level of 120, and are still getting an error in SSMS that "could not find method .STContains for type Microsoft.SQLServer.Types.SQLGeography in assembly Microsoft.SQLServer.Types" Do we need to install a service pack? a feature pack, or something? And I have tried different cases, like .STContains, .STcontains, and .stcontains. None work. – Baodad Oct 11 '17 at 23:18

3 Answers3

1

For a lot of my projects I create a folder at the project level (Visual Studio) called "libraries" where I put DLL's of this nature and other third party stuff. I don't know if that's standard practice, but everyone I work with has done this for a while and it's worked well in TFS and Subversion before that.

Anyway, mine is sitting in this directory (SQL 2012 / Win 7 / 64 bit OS):

C:\Program Files (x86)\Microsoft SQL Server\110\Shared

I copy it from that directory to the library folder in my project.

Eric
  • 2,273
  • 2
  • 29
  • 44
  • Thanks for the great response. I found it sitting in that directory. Where do I copy and paste it to if I'm trying to have access to these features in a certain database within SQL? –  Dec 09 '13 at 17:43
  • 2
    I just re-read your code, I think you might want to try correctly casing. As an example, STUnion will work but STunion won't. It's a little weird since T-SQL is otherwise so case insensitive. – Eric Dec 09 '13 at 18:17
0

I've encountered the same issue working with SQL Server 2016 LocalDB:

Could not find method 'STCrosses' for type 'Microsoft.SqlServer.Types.SqlGeography' in assembly 'Microsoft.SqlServer.Types'

It took me a while to understand that STCrosses is for geometry data type, while for geography I should use STIntersects.

Usurer
  • 213
  • 2
  • 6
0

The method name is case sensitive and expects STContains rather than stcontains

DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::Parse('CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (-122.200928    47.454094, -122.810669 47.00648, -122.942505 46.687131, -121.14624 45.786679, -119.119263  46.183634), (-119.119263 46.183634, -119.273071 47.107523, -120.640869 47.569114, -122.200928 47.454094)))');
SET @h = geography::Parse('POINT(-121.703796 46.893985)');

select @g.STContains(@h)
scottyc
  • 80
  • 7