Unable to load SqlServerSpatial.dll

VBAHole picture VBAHole · Jan 10, 2013 · Viewed 51.3k times · Source

I am trying to use the SqlServer Spatial CLR types in a C# .Net project. I want to use SqlGeometry to query spatial records out of my db.

I have this working on my local machine in a unit test running in Visual Studio 2010 hitting a remote SqlServer machine. All good.

I then publish a WCF Rest service to my local IIS instance that has a service that hits the same class library as the unit test to do some spatial querying and it fails.

I get an error saying

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

I have googled this and found many, many answers - none work for me. I have:

  • registered the CLR types with the GAC
  • install the 64-bit, and later also, the 32-bit version of the VC++
  • tried many variations of using different Microsoft.SqlServer.Types dll versions

The only thing I have not done, and frankly refuse to do, is to install anything on the actual SqlServer box. This seems unnecessary to me.

At this point the only thing that I can think is causing this is a permissions issue because it is running in an IIS app pool and not inside Studio where it works in the unit test.

Note that in my project I NEVER make reference to the dll mentioned in the error message. That dll is present on the sql box but I can't add it to studio as it gives some message when i try to. I'm running out of things to try here. It's 90's dll hell all over again.

Answer

Marcelo Mason picture Marcelo Mason · Feb 10, 2013

I had the same problem on a Windows Server 2012 machine. It had an SqlServerSpatial110.dll file in \Windows\System32, but no SqlServerSpatial.dll. The solution was installing the Microsoft System CLR Types for SQL Server 2008 R2 on the machine.

  1. http://www.microsoft.com/en-us/download/details.aspx?id=26728
  2. Click Download
  3. Check off one of these depending on your processor architecture:

    • 1033\x64\SQLSysClrTypes.msi
    • 1033\x86\SQLSysClrTypes.msi
    • 1033\IA64\SQLSysClrTypes.msi
  4. Click Next