ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Create Database Connection

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Creates a file that ArcGIS uses to connect to a database or an enterprise, a workgroup, or a desktop geodatabase.

Usage

  • After valid connection information is entered to establish a connection on the tool dialog box, the tool will connect to the database to determine if it contains the geodatabase schema.

    • For databases, all the parameters in the Geodatabase Connection Properties section of the tool dialog box are ignored.
    • For geodatabases, the tool automatically populates the Geodatabase Connection Properties section. The Schema parameter is set with the sde schema (for Oracle user schema geodatabases only), the default Version Type for the geodatabase, and the Default version.
  • If you don't want to save your connection information in the Results window or don't want to store it in the geoprocessing history log files, disable history logging and save the connection file without saving the connection information.

  • Connections from ArcGIS to Altibase and Netezza are no longer supported.

Syntax

arcpy.management.CreateDatabaseConnection(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) will be stored.

Folder
out_name

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

String
database_platform

Specifies the database management system platform to which the connection will be made. The following are valid options:

  • DAMENG —Connect to Dameng.
  • DB2 —Connect to IBM Db2 for Linux, UNIX, or Windows.
  • DB2ZOS —Connect to IBM Db2 for z Operating System.
  • INFORMIX —Connect to IBM Informix.
  • ORACLE —Connect to Oracle or Amazon Relational Database Service (RDS) for Oracle.
  • POSTGRESQL —Connect to PostgreSQL, Amazon Aurora (PostgreSQL-compatible edition), Amazon Relational Database Service (RDS) for PostgreSQL, or Microsoft Azure Database for PostgreSQL.
  • SAP HANA —Connect to SAP HANA.
  • SQL_SERVER —Connect to Microsoft SQL Server, Microsoft Azure SQL Database, Microsoft Azure SQL Managed Instance, or Amazon Relational Database Service (RDS) for SQL Server.
  • TERADATA —Connect to Teradata Data Warehouse Appliance.
String
instance

The database server or instance to which the connection will be made.

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 varies, depending on the database platform you specified.

See below for information about what to provide for each database platform.

  • Dameng—The name of the server where the Dameng database is installed
  • 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
  • PostgreSQL—The name of the server where PostgreSQL is installed or the name of the PostgreSQL database service instance
  • SAP HANA—The ODBC data source name for the SAP HANA database
  • SQL Server—The name of the SQL Server database instance or the name of the database service instance.
  • Teradata—The ODBC data source name for the Teradata database
String
account_authentication
(Optional)

Specifies the type of authentication that will be used.

  • DATABASE_AUTH —Database authentication will be used. An internal database user name and a password will be used to connect to the database. 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.
    Note:

    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_AUTH —Operating system authentication will be used. You do not need to type a user name and password. The connection will be made with the user name and password that were 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.
Boolean
username
(Optional)

The database user name that will be used for database authentication.

String
password
(Optional)

The database user password that will be used for database authentication.

Encrypted String
save_user_pass
(Optional)

Specifies whether the user name and password will be saved.

  • SAVE_USERNAME —The user name and password will be saved 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 save a user name and password.
  • DO_NOT_SAVE_USERNAME —The user name and password will not be saved in the connection 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 to which the connection will be made. This parameter only applies to PostgreSQL and SQL Server platforms.

String
schema
(Optional)

The user schema geodatabase to which the connection will be made. 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 sde schema geodatabase.

String
version_type
(Optional)

Specifies the type of version to which the connection will be made.

  • TRANSACTIONAL —Connect to a transactional version.
  • HISTORICAL —Connect to an historical marker.
  • POINT_IN_TIME —Connect to a specific point in time. If POINT_IN_TIME is used, the version parameter will be ignored.

Note:

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 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 which the connect will be made. The default option uses the default transactional version.

String
date
(Optional)

The value representing the date and time that will be used to connect to the database when working with archive-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

Note:

  • 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

Derived Output

NameExplanationData Type
out_workspace

The output database connection file (.sde).

workspace

Code sample

CreateDatabaseConnection example 1 (Python window)

The following Python window script demonstrates how to use the CreateDatabaseConnection function in immediate mode.

import arcpy
arcpy.CreateDatabaseConnection_management("C:\\MyProject",
                                          "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 function.

# 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("C:\\MyProject",
                                          "zion.sde",
                                          "ORACLE",
                                          "zionserver/ORCL",
                                          "OPERATING_SYSTEM_AUTH")
CreateDatabaseConnection example 3 (Python window)

The following Python window script demonstrates how to use the CreateDatabaseConnection function 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("C:\\MyProject",
                                          "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 function 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("C:\\MyProject",
                                          "history.sde",
                                          "POSTGRESQL",
                                          "dbserver",
                                          "DATABASE_AUTH",
                                          "stevie",
                                          "smith",
                                          "SAVE_USERNAME",
                                          "archivedb",
                                          "#",
                                          "POINT_IN_TIME",
                                          "#",
                                          "5/19/2011 8:43:41 AM")

Environments

  • Current Workspace

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics

  • An overview of the Workspace toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2021 Esri. | Privacy | Legal