Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using ogr2ogr from OSGeo4W on my Windows 7 box to import a shapefile into a SQL Server database on one of my servers. I was able to successfully complete the conversion using shp2sqlserver, but I can't figure out why it fails when I try the same thing with ogr2ogr directly.

Here's the syntax of my ogr2ogr command:

ogr2ogr -f MSSQLSpatial "MSSQL:server=[server];database=[dbname];User Id=[uid];Password=[pwd]" C:\Path\to\file\shapefile.shp

When I run this, it fails first with an error saying "Cannot open database [dbname] requested by the login. The login failed." Next is another error that the "MSSQL Spatial driver doesn't currently support database creation. Please create database with the Microsoft SQL Server Client Tools."

I have checked and double-checked that the user id and password given works properly, that there is already a database with the name given (I substituted [dbname] here to speak in generalities), and that the database is owned by the user.

As mentioned, I was able to do this with shp2sqlserver so I don't think it's my database setup that is the problem. Is there a problem with my connection string? Is there some peculiarity within ogr2ogr that I'm not aware of?

I am using a Windows 7 machine connecting to SQL Server 2008 R2. Gdal is version 1.9.1.

share|improve this question
The ODBC documentation suggests keywords UID and PWD instead of User ID and Password. – klewis Oct 11 '12 at 21:21
Yeah. I tried that earlier but still no luck. – spencerrecneps Oct 11 '12 at 21:34
Never mind. I substituted uid and pwd as you directed and it works now. I must have had some other error causing problems before I started messing with the uid and pwd designation. Thanks! – spencerrecneps Oct 11 '12 at 21:39
Congrats on figuring out the problem. Since you did come up with an answer, it would be great if you would post it as an actual answer, possibly with a shoutout to @klewis, so that someone in a similar situation may be assisted. – Get Spatial Oct 11 '12 at 23:21
There is something unexpected I have come across, which is as given below: > > COMMAND USED: > > C:\Program Files\QGISDufour>ogr2ogr -overwrite -f “ESRI Shapefile” > “D:\Abhinav-Task\temp\sqlexport.shp” ” > MSSQL:server=WIN12;database=MAPS;tables=dbo.OGRExportTestTable;UID=RD; > PWD=test1 > ;”-sql “SELECT shapeid, shapename, shapegeom, bufferedshape.ToString(), bufferedshapearea area FROM > OGRExportTestTable WHERE shapegeom.STGeometryType() = ‘POINT’” > > > ERROR MESSAGE: > > > FAILURE: Couldn’t fetch requested layer ‘SELECT shapeid, shapename, > shapegeom, bufferedshape.ToString(), > – abhinavgoyal02 Apr 25 '14 at 11:14
up vote 6 down vote accepted

The ODBC documentation suggests keywords UID and PWD instead of User ID and Password.

share|improve this answer
This also fixed my errors about not being a Trusted Connection... – Tom Halladay Aug 28 '13 at 19:54
Still a good answer in 2016--it helped my out. – Jay Cummins Jan 13 at 17:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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