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

Several ArcPy functions take strings as geodatabase identifiers. I've looked through the ESRI docs, but can't find a good reference for the various acceptable formats. I'm looking for examples of each of the different kinds of geodatabases (personal geodatabase, file geodatabase, remote geodatabase).

For example,

gdb = "C:/MyData/PersonalGeodatabase.mdb"    # personal geodatabase
gdb = "C:/MyData/FileGeodatabase.gdb"        # file geodatabase
gdb = ""                                     # named instance SQL Server Express
gdb = ""                                     # sde database in SQL Server

If possible I would prefer that there not be a corresponding entry in ArcCatalog to make this work. The current working examples I have seen here all seem to rely on specifically named connections in ArcCatalog.

share|improve this question

While this does not answer your question about the connection string, I think it will be helpful. In ArcGIS 10.1, there is a new "Create Database Connection" geoprocessing tool that will allow you to create your connections on demand.

This means that you will also be able to create new database connections via arcpy scripting in Python. That way you will not have to rely on a a previously created entry in ArcCatalog.

import arcpy

arcpy.CreateDatabaseConnection_management("Database Connections", "utah.sde", "SQL_SERVER", "utah", "DATABASE_AUTH", "gdb", "gdb", "SAVE_USERNAME", "garfield", "#", "TRANSACTIONAL", "sde.DEFAULT"
share|improve this answer
That is helpful. I had seen this Create ArcSDE Connection File (Data Management) for ArcGIS 10.0 and wondered if that would do what I needed. After seeing your post, I would guess not. It also seems to imply that I will need to create a connection in ArcCatalog and use that to connect to RDBMS-based geodatabases. – mwolfe02 Aug 27 '12 at 16:19
The tool you linked works the same way, it creates a .sde file that you can then use with arcpy/geoprocessing. You can create and delete the file in your script if you don't want to add it to ArcCatalog. And if you did, you would have to put it in the Database Connections folder (which is an alias/shortcut to %APPDATA%\ESRI\Desktop10.0\ArcCatalog but you can use "Database Connections" within arcpy). – blah238 Aug 27 '12 at 19:49

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.