Wednesday 18 July 2018

gdal - Why does ogr2ogr SHP import error out trying to create a database?



All,


Can anyone tell me what the error is with OGR2OGR when trying to import a .SHP into MSSQLSPATIAL?


ERROR 1: MSSQL Spatial driver doesn't currently support database creation.
Please create database with the Microsoft SQL Server Client Tools.
MSSQLSpatial driver failed to create MSSQL:server=[]\[];database
=[];uid=[];pwd:[]

The import statement I'm using is this:


ogr2ogr -f MSSQLSpatial "MSSQL:server=[]\[];database=[];uid=[];pwd:[]" C:\[path to file]\police_districts_2877.shp -a_srs EPSG:2877 -lco "GEOM_TYPE=geometry" -lco "GEOM_NAME=geom" -nln "CCD_PoliceDistricts" -progress


As you can see, I'm not trying to create a database, and there is one already created. as per the 'creation issue' cited here: http://www.gdal.org/ogr/drv_mssqlspatial.html


I have followed several posts, including this: Shapefile to MSSQL with ogr2ogr fails to make connection, to no avail...


EDIT: I'm also getting a connection error, but I can't see why...I think my syntax is correct:


ERROR 1: Unable to initialize connection to the server for MSSQL:server=[]\[];database=[];uid=[];pwd:[],[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '[username]'.

Thanks!


-m



Answer



From past experience, I wouldn't trust that error message to strictly relate to database creation - I would treat it as just implying that there is a permissions issue of sorts with that connection string.


The first thing I'd do is use ogrinfo to check whether a connection can be made at all to that server/db using those credentials. Try running the following command (inserting your details into the placeholders as before):



ogrinfo "MSSQL:server=[]\[];database=[];uid=[];pwd=[]"

You should get a success message similar to "INFO: Open of MSSQL:server=...;database=...;uid=...;pwd=...' using driverMSSQLSpatial' successful. If you don't get a successful connection, you need to double-check basic things - is the SQLServer configured to allow remote connections, is there a firewall blocking access, are there any typos in the server/db/uid/pwd?


Assuming that you can connect ok to the database, the next thing to do would be to check the permissions of the user that you are using to connect. Although you correctly point out that you are not creating a new database, you are creating a new table (via the -nln option) - and OGR2OGR also creates two additional metadata tables ("geometry_columns" and "spatial_ref_sys") if they don't already exist in the target database - does the user have permission to create tables?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...