[gdal-dev] ogr2ogr doesn't connect to MS SQL Server

Reetz, Michael (NLPV) Michael.Reetz at nlpvw.niedersachsen.de
Thu Oct 20 07:11:07 PDT 2022


Dear members of the GDAL-DEV group,

we are using MS SQL Server 2019 as basis for Geoserver and GIS software. There are a lot of tables that have attributes of the types geometry and/or geography. I can load these tables into QGIS (3.22.8) projects without any problems.

Now I'm asked to add an geography attribute to one table that has already an geometry attribute and populate it with coordinates by transforming the geometry values. I've found code how to do this with ogr2ogr here:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/335d3f6b-11f4-4e02-8d6d-b49cb59ed98d/using-ogr2ogr-to-reproject-within-a-sql-table?forum=sqlspatial


Since ogr2ogr is part of the OSGeo4W Shell installed with QGIS, I've tried to run this command there.

ogr2ogr -f "MSSQLSpatial" "MSSQL:server=<my server IP>;driver=ODBC Driver 17 for SQL Server;database=<my database>;trusted_connection=yes;" "MSSQL:server=<my server IP>;driver=ODBC Driver 17 for SQL Server;database=<my database>;trusted_connection=yes;" -sql "SELECT <my attributes>, GEOM.STAsBinary(), WGS84 FROM <my table>" -s_srs "EPSG:25832" -t_srs "EPSG:4326" -update -lco "GEOM_TYPE=geography" -lco "GEOM_NAME=WGS84" -nln "<my table>"

But I receive the error message:

"Unable to open datasource `MSSQL:server=<my server IP>;driver=ODBC Driver 17 for SQL Server;database=<my database>;trusted_connection=yes;' with the following drivers. ..."

MSSQLSpatial is not listed.


I've tried some other commands but all with MSSQL in it leads to an error.

Any idea what I can do to make it run?

Thanks in advance and best regards,

Michael


Mit freundlichen Grüßen
Im Auftrag

Michael Reetz

*****************************************
Michael Reetz
Datenbanken und Anwendungsentwicklung
Nationalpark-Verwaltung Niedersächsisches Wattenmeer
Virchowstr. 1 | 26382 Wilhelmshaven
Tel.: +49 (0) 4421 911 291
e-mail: michael.reetz at nlpvw.niedersachsen.de<mailto:michael.reetz at nlpv-wattenmeer.niedersachsen.de>
Web: https://www.<https://www./>nationalpark-wattenmeer.de
[cid:image001.png at 01D8E49E.8F2A2820]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221020/adbeae2f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6534 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221020/adbeae2f/attachment-0001.png>


More information about the gdal-dev mailing list