1

I have shapefiles with geographic data (polygon geometry only) that I'd like to import into tables in a SQL Server instance over which I have no direct control (but I'm working closely with someone that is willing and able to help with that part but needs some direct guidance). The specific product is Microsoft SQL Server Enterprise: Core-based Licensing (64-bit). I don't have rights to create the tables myself so I'm having to "relay instructions" to my helper.

In researching how to go about this, I found that SQL Server doesn't have any built in functionality, but I ran across several people with a similar issue who had success using "ogr2ogr." I downloaded the OSGeo4W Network installer from https://trac.osgeo.org/osgeo4w. I've gotten as far as running the installer and getting the ogr2ogr.exe and related dlls all accessible to my helper. He launched a DOS command prompt and typed ogr2ogr and we saw the help info, so I think the basics are all "there." However, when we issued a complete command to attempt an actual table load from shapefile to an existing database on SQL Server, we see the error message: "Unable to find driver mssqlspatial."

I've researched here at gis.stackexchange and elsewhere and have seen some questions and answers that seem to be in the ballpark but basically I'm just a bit lost about a good next step. Is it true that I need to download a file called "mssqlspatial.dll?" I've seen references to a file named "ogr_mssqlspatial.dll." Is that the same thing or is it different? Where do I get hold of the driver? I couldn't seem to find anything at Microsoft's driver downloads. Does the driver need to be on the server that houses the SQL Server instance or on my helper's laptop?

I launched the osgeo4w-setup.exe and selected the "advanced install" option and carefully reviewed all the packages available; I still didn't find anything named "mssqlspatial" or close to that.

2 Answers 2

1

See my answer here for a little more detail, but what happens if you add this to your ogr2ogr command?

--config MSSQLSPATIAL_USE_BCP NO

0

I had this on a new server where we have ogr2ogr installed to import shp files via a batch process.

I tried osgeo4w and selected to install everything. This takes hours, and after all that ogr2ogr.exe reports "unable to find driver mssqlspatial". Duh.

The previous server was cobbled together in development, so I didn't know exactly why it was working. It had QGIS installed for example, and that comes bundled with ogr2ogr too. This new machine needs to be "clean" without any bloat.

So to get a minimum install...

  1. Download GDAL from Tamas Szekeres which comes with ogr2ogr.

There are lots of confusing downloads there. You need to click one of the download links, it doesn't download the whole package, you can then select just the GDAL rather than mapserver or anything else you don't want. At the time the best download for me was

gdal-3.6.2-1930-x64-core.msi 2023-02-08 09:51:24 34752 kB Generic installer for the GDAL core components

  1. Install it. You need "custom install", and select the MSSQL driver. Then add C:\Program Files\GDAL to your SYSTEM PATH

enter image description here

  1. I had to add PROJ_LIB environment variable with path C:\Program Files\GDAL\projlib to get mine to work.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.