4

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.

1 Answer 1

5

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"
2
  • 1
    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, 2012 at 16:19
  • 2
    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, 2012 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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