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.