Windows 10; GDAL 3.3.1; QGIS 3.2; SS2019;

When attempting to load any shapefile into SQL Server 2019 I'm getting column headers but no rows are importing. I've tried:

  • Different versions of QGIS (QGIS versions 3.4.11 and 3.2 with the respective OSGeo4W downloads, as mentioned in another thread);

  • Various tutorials on the net with the respective shapefiles used; and

  • Read every article I can find relating to uploading shapefiles to SQL Server.

The command I'm using is:

ogr2ogr -f "MSSQLSpatial" "MSSQL:server=MYSERVER;database=DBNAME;trusted_connection=yes;" "SHAPEFILE LOCATION" -lco GEOMETRY_NAME=GEOM -lco GEOM_TYPE=GEOMETRY -nln "NAME OF TABLE" -a_srs "EPSG:4326"

Of course, when following the tutorials I'm using the command exactly as they have it structured and again, using the files they're using but I'm only getting column headers with no rows in MSSMS. I've tried specifying drivers as mentioned here (GDAL ogr2ogr into SQL Server Bulk Insert (BCP) not working). I've checked the CRS in every case to make sure it matches the command before attempting to upload.

On a similar post (Import shapefile to SQL Server 2019 using OGR2OGR), a user said:

I then updated to qGIS 3.20.1 with GDAL 3.3.1, released 2021/06/28 and now I get no rows.

I'm on day three of trying to figure this one out with multiple installs, mods, tweaks, tutorials, etc. What is wrong here?

  • Could you share the shapefile? Aug 27, 2021 at 7:21
  • You can try adding this to your command: -append --config OGR_TRUNCATE YES. This clears the content of the table and fills it again. Aug 27, 2021 at 7:42
  • I ran append for different files and OSGeo4W appears to be working for about two seconds before completing with no errors. Upon refresh of SS I'm still getting just the header columns. Here is a link to a file I've tried to upload - projected to 4326.
    – Erik
    Aug 27, 2021 at 16:05
  • Thanks for that shapefile. I managed to insert all the data (in this case in my postgresql server). I think the problem is that the shapefile geometry is multipolygon and the sql table wants to default to polygon. Adding -nlt PROMOTE_TO_MUTLI to the command fixed it for me. Let me know if it worked for you Aug 30, 2021 at 8:45
  • I'm having the same problem. No error message, it creates the table and no rows get added. I'm pulling from a fileGDB though. It works fine going into postgres but not sql server. I added -nlt PROMOTE_TO_MULTI and it had no effect.
    – jport
    Jun 14, 2022 at 16:09


Your Answer

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

Browse other questions tagged or ask your own question.