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.

  • 1
    The ODBC documentation suggests keywords UID and PWD instead of User ID and Password.
    – klewis
    Oct 11, 2012 at 21:21
  • Yeah. I tried that earlier but still no luck. Oct 11, 2012 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! Oct 11, 2012 at 21:39
  • 1
    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. Oct 11, 2012 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(), > Apr 25, 2014 at 11:14

2 Answers 2


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

  • 1
    This also fixed my errors about not being a Trusted Connection... Aug 28, 2013 at 19:54
  • Still a good answer in 2016--it helped my out. Jan 13, 2016 at 17:30

This is working for me in windows command prompt:

ogrinfo "MSSQL:server=someserver;database=databasename;UID=username;PWD=password123"

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.