0

I have a scenario in which I need to calculate the distance between to addresses. I've seen numerous examples using DbGeography in the System.Data.Entity namespace, however I seem to run my head against the wall since my application cannot load SqlServerSpatial110.dll library.

I've read several articles and SO's regarding this specific issue, but none of them seem to work for me, hence the reason for this SO, hoping to find some other angle to my specific scenario.

Environment

  • I've added the Microsoft.SqlServer.Types library from NuGet.
  • I've added the SqlServerSpatial110.dll´ file from my folder:Windows/System32`

I'm trying to calculate the distance like this:

var loc1 = DbGeography.FromText(string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", someLatitude, someLongitude));
var loc2 = DbGeography.FromText(string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", someLatitude, someLongitude));

var distance = loc1.Distance(loc2);

Problem
Whenever I try to run my application, and this code is run, I get an exception:

Unable to load DLL SqlServerSpatial.dll : The specified module could not be found.

I've seen this error happen to other people, but I have yet to find a possible solution.

I suppose the exception is thrown because it cannot load the library (as it says so), but I can't figure WHY it cannot load the library. As mentioned, I took the SqlServerSpatial110.dll from my Windows/System32 folder, as many people suggested this was were to find the correct DLL.

Any suggestions or possible fixed are much obliged.

So far, I've been able to fix this issue using the System.Device namespace instead. This works a bit different, and I'm pretty sure this isn't driven in the database, but inside my application instead. I'd rather have this done in the database, as performance could be heavily decreased the more entries I get.

Detilium
  • 2,868
  • 9
  • 30
  • 65
  • Not related to your current problem, but be aware that you're passing lat/long the wrong way around. `POINT( )` is the text you need to build – Damien_The_Unbeliever May 30 '17 at 13:20
  • Possible duplicate of [Unable to load DLL 'SqlServerSpatial.dll'](https://stackoverflow.com/questions/16868326/unable-to-load-dll-sqlserverspatial-dll) – NightOwl888 May 30 '17 at 14:06
  • Make sure you uncheck the "prefer 32 bit" default option in Visual Studio Project Properties. Apparently the DLL only works in 64 bit. You may also need the 64 bit of IIS Express. – NightOwl888 May 30 '17 at 14:07

0 Answers0