Skip to main content

Connect to Db2 from ArcGIS

The following list summarizes the steps required to connect from ArcGIS to an IBM Db2 database, including a database that contains a geodatabase:

These tasks are described in the following sections.

Install the Db2 client

If Db2 and the ArcGIS Server site to which you want to publish are running on separate servers, install a Db2 client on all machines in the ArcGIS Server site.

Install the 64-bit Db2 client on all ArcGIS machines that need to connect to a Db2 database. You can obtain Db2 client files from IBM or from My Esri. Follow the instructions provided with the Db2 client software to install it. If you do not have the privileges necessary to install software on the machines where ArcGIS clients are running, you'll need to have your IT department install the Db2 client for you.

Configure a data source name (optional)

After you install the Db2 client software, you can catalog a Db2 database, thereby creating a data source name to be used when you register your database with an ArcGIS Server site.

Note:

If ArcGIS Server is installed on a Linux machine that is separate from your Db2 server, you must create a Db2 client instance on the ArcGIS Server machine before you can catalog the Db2 instance.

If you choose not to catalog a database, you must specify a DSNless connection string to connect to a Db2 database in the form HostName=<host>;Port=<port number>;Database=<database name>;. See Database connections in ArcGIS Pro for more information and an example.

Edit the init_user_param.sh script

After you install the database client files, alter the init_user_param.sh script installed with ArcGIS Server to reference the client files. You can access this script by browsing to the <ArcGIS Server installation directory>/arcgis/server/usr directory.

You must update the init_user_param.sh on every machine in the ArcGIS Server site.

You must update the init_user_param.sh on every machine in the ArcGIS Server site.

Note:

If your user profile references the Db2 client and the client information differs between the user profile and init_user_param.sh, ArcGIS Server may experience problems when attempting to connect to the database. To alleviate connection issues, remove the reference information from your user profile and reference the database client libraries again using the following steps:

  1. Ensure that the ArcGIS Server installation owner on each machine has at least read and execute permissions on the database client libraries.

  2. Open the init_user_param.sh script in a text editor.

  3. Remove the comment marks (#) from the lines beginning with export.

    #
    # Modify this section to configure a connection to Db2
    export DB2_CLIENT_HOME=<DB2_InstallDir>
    export DB2INSTANCE=<DB2_instance_name>
    export PATH=DB2_CLIENT_HOME/bin:$PATH
    export LD_LIBRARY_PATH=$DB2_CLIENT_HOME/lib64:$LD_LIBRARY_PATH
    
  4. Replace <DB2_InstallDir> with the location of the Db2 client installation directory, and replace <DB2_instance_name> with the name of your Db2 instance.

    For example, if the Db2 client is installed to /home/db2prod and the Db2 instance is named db2prod, the file would look as follows:

    #
    # For connection with Db2
    #
    export DB2_CLIENT_HOME=/home/db2prod
    export DB2INSTANCE=db2prod
    export PATH=DB2_CLIENT_HOME/bin:$PATH
    export LD_LIBRARY_PATH=$DB2_CLIENT_HOME/lib64:$LD_LIBRARY_PATH
    
  5. Save and close the script.

  6. For the changes you made in the init_user_param.sh file to take effect, you must restart ArcGIS Server.

    To do this, run the stopserver.sh script, then run the startserver.sh script on each machine in the ArcGIS Server site.

    ./stopserver.sh

    ./startserver.sh

Create a database connection

You must have a database connection (.sde file) that authenticates the connection to the database.

You can call the ArcPy CreateDatabaseConnection function from one of the machines in the ArcGIS Server site that needs to connect to the database. See Create Database Connection in the ArcGIS Pro help for information about running this function.

The following information is specific to creating a database connection file for use with ArcGIS Server:

  • You must save database-authenticated user information with the connection file.

  • If you use operating system authentication to connect, ensure your Db2 server can authenticate the ArcGIS Server account.

Grant privileges

The login used to connect to the database must have specific privileges granted to it. For logins that will only publish read-only services (such as map services), grant the privileges necessary for a data viewer, as described in Privileges for geodatabases in Db2 or Privileges for using ArcGIS with a Db2 database. For logins that will publish editable feature services, grant the privileges necessary for a data editor.

If your connection to Db2 uses operating system authentication, grant the appropriate privileges to the ArcGIS Server account.

If the data is in a geodatabase, the data owner must grant the required privileges to the data. If the data is in a database, the data owner can grant privileges from ArcGIS or the database administrator can use database tools to grant the required privileges.

Register with ArcGIS Server

To publish web services that use the data in the Db2 database or geodatabase in Db2 without copying data, you must register the database with your ArcGIS Server sites. You can use a data source name when registering the database—in which case you must catalog the database before registering—or you can provide a string of connection information (referred to as a DSNless connection).

You can use the database connection file you created to register the database with ArcGIS Server from the Manage registered data stores pane in ArcGIS Pro or from ArcGIS Server Manager.