2

I'm importing a shapefile into SQL Server '12 via the OGR2OGR tool and am getting a database connection error.

I followed the example from this article.

What I ran:

ogr2ogr -overwrite -f ESRI Shapefile "MSSQL:Server=.\MSSQLSERVER2012;database=ap;trusted_connection=yes" "C:\Users\johndoe\Desktop\myshapefile.shp"

The error:

SQL Server does not exist or access denied

I'm assuming I need to pass some type of credentials? and the server string is probably wrong where would it be located.

Question: Why am I getting this error?

  • how about omitting the .\ in the MSSQL connection string? – DPSSpatial Oct 28 '16 at 20:09
  • @DPSSpatial hey! I just tried that no luck, same error. – Jordan Davis Oct 28 '16 at 20:11
  • Hmm... then what about using uid and pwd instead of trusted connection? – DPSSpatial Oct 28 '16 at 20:13
  • First thing to correct is the value of -f that is telling the outputformat. In your case it should point to SQL server. – user30184 Oct 28 '16 at 20:21
  • I just tried uid I'm assuming "user id" I've seen some examples that say username though. – Jordan Davis Oct 28 '16 at 20:22
1

One thing that I found was that I was not able to upload shapefiles directly to an MSSQL instance that was on a separate server; my workaround was to download sql express to my local hard drive, do the OGR2OGR script there, then use SQL Server Management studio to import the data from my local computer to the server on the network domain. My syntax was (from the command prompt in the directory that ogr2ogr.exe is in):

ogr2ogr -progress -f "MSSQLSpatial" "MSSQL:server=(your server name here);database=(database name on server to publish shapefile to);trusted_connection=yes" "(directory and actual name of shapefile with .shp extension)" -a_srs "(the ESPG projection code of the shapefile)" -lco PRECISION=NO

Note: the "trusted connection" parameter is used when you are using windows authentication (e.g., when you are on a domain network) as MSSQL login credentials. You may want to check if your mssql server is set up to accept forms of login other than username/pw (you may need to install another instance of sql server; the only place I saw that option was when I ran the original setup.exe)

  • Yeah very close to what I ended up using. – Jordan Davis Nov 1 '16 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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