Create Database Connection (Data Management)
Summary
Creates a connection file that can be used to connect to an enterprise database or ArcSDE geodatabase.
Usage
When using the tool dialog box, if valid connection information is entered the tool will connect to the database in order to determine if the database contains the geodatabase schema. If the schema is found, the server will automatically populate the Schema parameter with the SDE schema (for Oracle user schema geodatabases only), the Version Type parameter with the TRANSACTIONAL keyword, and the version name parameter with the Default version name.
If you want to prevent your connection information from being saved in the Results window or stored in the geoprocessing history log files, you will need to disable history logging and save the connection file without saving the connection information you wish to hide.
All of the parameters in the Geodatabase Connection Properties section of the tool dialog box are ignored when connecting to an enterprise database that is not a geodatabase.
Syntax
Parameter | Explanation | Data Type |
out_folder_path |
The folder path where the .sde file will be stored. | Folder |
out_name |
The name of the .sde file. The output file extension must end with .sde. | String |
database_platform |
The DBMS platform that will be connected to. Valid options are:
| String |
instance | The server or instance to connect to. The value you choose from the Connection type drop-down list indicates the type of database to which you want to connect. The information you provide for this parameter will vary, depending the connection type you choose. See below for further information specific to each DBMS platform.
| String |
account_authentication (Optional) |
| Boolean |
username (Optional) |
The database user name to connect with using Database Authentication. | String |
password (Optional) |
The database user password when using Database Authentication. | Encrypted String |
save_user_pass (Optional) |
| Boolean |
database (Optional) |
The name of the database that you will be connecting to. This parameter only applies to PostgreSQL and SQL Server platforms. | String |
schema (Optional) | The user schema geodatabase to connect to. This option only applies to Oracle databases that contain at least one user-schema geodatabase. The default value for this parameter is to use the Default version. | String |
version_type (Optional) | The type of version you wish to connect to.
If TRANSACTIONAL or HISTORICAL is used, the date parameter will be ignored. If HISTORICAL is used and a name is not provided in the version_name parameter, the Default transactional version will be used. If POINT_IN_TIME is used and a date is not provided in the date parameter, the Default transactional version will be used. | String |
version (Optional) |
The geodatabase transactional version or historical marker to connect to. The default option will use the Default version. | String |
date (Optional) | The value representing the date and time used to connect to the database. For working with archiving enabled data. Dates can be entered in the following formats:
Note:
| Date |
Code Sample
The following Python window script demonstrates how to use the CreateDatabaseConnection tool in immediate mode.
import arcpy
arcpy.CreateDatabaseConnection_management("Database Connections",
"utah.sde",
"SQL_SERVER",
"utah",
"DATABASE_AUTH",
"gdb",
"gdb",
"SAVE_USERNAME",
"garfield",
"#",
"TRANSACTIONAL",
"sde.DEFAULT")
The following stand-alone script demonstrates how to use the CreateDatabaseConnection tool.
# Name: CreateDatabaseConnection2.py
# Description: Connects to a database using Easy Connect string
# and operating system authentication.
# Import system modules
import arcpy
# Run the tool
arcpy.CreateDatabaseConnection_management("Database Connections",
"zion.sde",
"ORACLE",
"zionserver/ORCL",
"OPERATING_SYSTEM_AUTH")
The following Python window script demonstrates how to use the CreateDatabaseConnection tool to connect to an historical marker.
# Name: CreateDatabaseConnection3.py
# Description: Connects to a geodatabase historical marker using a
# cataloged DB2 database and database authentication.
# Import system modules
import arcpy
# Run the tool
arcpy.CreateDatabaseConnection_management("Database Connections",
"history.sde",
"DB2",
"DB2_DS",
"DATABASE_AUTH",
"butch",
"sundance",
"SAVE_USERNAME",
"#",
"#",
"HISTORICAL",
"June 9, 2010",
"#")
The following Python window script demonstrates how to use the CreateDatabaseConnection tool to connect to a point in time.
# Name: CreateDatabaseConnection4.py
# Description: Connects to a point in time in the geodatabase in
# PostgreSQL using database authentication.
# Import system modules
import arcpy
# Run the tool
arcpy.CreateDatabaseConnection_management("Database Connections",
"history.sde",
"POSTGRESQL",
"dbserver",
"DATABASE_AUTH",
"stevie",
"smith",
"SAVE_USERNAME",
"archivedb",
"#",
"POINT_IN_TIME",
"#",
"5/19/2011 8:43:41 AM")