Create Database Connection (Data Management)

License Level:BasicStandardAdvanced

Summary

Creates a connection file that can be used to connect to a database or an enterprise, workgroup, or desktop geodatabase.

Usage

Syntax

CreateDatabaseConnection_management (out_folder_path, out_name, database_platform, instance, {account_authentication}, {username}, {password}, {save_user_pass}, {database}, {schema}, {version_type}, {version}, {date})
ParameterExplanationData Type
out_folder_path

The folder path where the database connection file (.sde file) will be stored.

Folder
out_name

The name of the database connection file. The output file will have the extension .sde.

String
database_platform

The DBMS platform that will be connected to. Valid options are

  • SQL_SERVERFor connecting to Microsoft SQL Server
  • ORACLEFor connecting to Oracle
  • DB2For connecting to IBM DB2 on Linux, UNIX, or Windows
  • DB2ZOSFor connecting to IBM DB2 on z/OS
  • INFORMIXFor connecting to IBM Informix
  • NETEZZAFor connecting to IBM Netezza
  • POSTGRESQLFor connecting to PostgreSQL
  • TERADATAFor connecting to Teradata
String
instance

The database server or instance to which you will connect.

The value you specify for the database_platform parameter indicates the type of database to which you want to connect. The information you provide for the instance parameter will vary, depending the database platform you specified.

See below for further information on what to provide for each database platform.

  • DB2—The name of the cataloged DB2 database.
  • DB2 for Z/OS—The name of the cataloged DB2 database.
  • Informix—The Open Database Connectivity (ODBC) data source name for the Informix database.
  • Oracle—Either the TNS name or the Oracle Easy Connection string to connect to the Oracle database.
  • Netezza—The ODBC data source name for the Netezza database.
  • PostgreSQL—The name of the server where PostgreSQL is installed.
  • SQL Server—The name of the SQL Server instance.
  • Teradata—The ODBC data source name for the Teradata database.
String
account_authentication
(Optional)
  • DATABASE_AUTHDatabase Authentication. Uses an internal database user name and password to connect to the DBMS. You aren't required to type your user name and password to create a connection; however, if you don't, you will be prompted to enter them when a connection is established.
    NoteNote:

    If the connection file you are creating will provide ArcGIS services with access to the database or geodatabase, or if you want to use the Catalog search to locate data accessed through this connection file, you must type a user name and password.

  • OPERATING_SYSTEM_AUTHUse operating system authentication. You do not need to type in a user name and password. The connection will be made with the user name and password used to log in to the operating system. If the login used for the operating system is not a valid geodatabase login, the connection will fail. Also note, if you are creating a connection to a geodatabase stored in Oracle, DB2, or Informix, you must use a direct connection to the database.
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)
  • SAVE_USERNAMESave the user name and password in the connection file. This is the default. If the connection file you are creating will provide ArcGIS services with access to the database or geodatabase, or if you want to use the Catalog search to locate data accessed through this connection file, you must type a user name and password.
  • DO_NOT_SAVE_USERNAMEDo not save the user name and password in the file. Every time you attempt to connect using the file, you will be prompted for the user name and password.
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.

  • TRANSACTIONALUse to connect to a transactional version.
  • HISTORICALUse to connect to an historical marker.
  • POINT_IN_TIMEUse to connect to a specific point in time. If POINT_IN_TIME is used, the Version Name parameter will be ignored.

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:

  • 6/9/2011 4:20:15 PM
  • 6/9/2011 16:20:15
  • 6/9/2011
  • 4:20:15 PM
  • 16:20:15

NoteNote:

  • If a time is entered without a date, the default date of December 30, 1899, will be used.
  • If a date is entered without a time, the default time of 12:00:00 AM will be used.

Date

Code Sample

CreateDatabaseConnection example 1 (Python window)

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")
CreateDatabaseConnection example 2(stand-alone script)

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")
CreateDatabaseConnection example 3 (Python window)

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",
                                          "#")
CreateDatabaseConnection example 4 (Python window)

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")

Environments

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015