English

How To: Programmatically update a password change in an ArcGIS Server registered data store

Summary

In some cases, it is necessary to perform a scheduled password change on a data source registered in ArcGIS Data Store such as a database to maintain secured access. This is possible by manually importing the .sde connection file from ArcGIS Server. However, with multiple .sde files to be imported, the process can be tedious for an organization. The arcgis.gis module in ArcGIS API for Python can automate the process.

This article provides steps to automate a password change in a registered data store.

Procedure

  1. Import the necessary modules.
from arcgis.gis import GIS
  1. Connect to the portal using an administrator account.
gis = GIS("https://machine_name.domain:7443/arcgis/home","username", "password", verify_cert=False)
print("connected")
  1. List all available servers in the portal.
dstores = server1.datastores.list()
dstores
  1. Create a connection string for the database to be updated using the generate_connection_string() method. The code generates a connection string to be used when creating a new data item.
server1.datastores.generate_connection_string(r"C:\Users\user\AppData\Roaming\ESRI\Desktop10.x\ArcCatalog\Sample.sde")
The sample image of the connection string.
  1. Find the index of datastore items from the listed datastores in Step 3.
ds = dstores[N]
ds
  1. Create a data item with the updated password.
pro2 = {
  "path": "/enterpriseDatabases/testDsfunc",  //a unique path on the server
  "type": "egdb", //as this is a database
  "info": {
    "dataStoreConnectionType": "shared",
    "isManaged": "false",
    "connectionString": "<Connection string result from step 4>"
  }
}
  1. Update the password in the data store.
ds.update(pro2)

The following shows the full code:

from arcgis.gis import GIS
 
gis = GIS("https://machine_name.domain:7443/arcgis/home","username", "username", verify_cert=False)
print("connected")
 
gis_servers = gis.admin.servers.list()
gis_servers
server1 = gis_servers[0]
 
dstores = server1.datastores.list()
dstores
 
server1.datastores.generate_connection_string(r"C:\Users\user\AppData\Roaming\ESRI\Desktop10.x\ArcCatalog\Sample.sde")

ds = dstores[9]
ds

pro2 = {
  "path": "/enterpriseDatabases/testDsfunc",  //a unique path on the server
  "type": "egdb", //as this is a database
  "info": {
    "dataStoreConnectionType": "shared",
    "isManaged": "false",
    "connectionString": "ENCRYPTED_PASSWORD=sample_1;SERVER=User;INSTANCE=sde:sqlserver:User;DBCLIENT=sqlserver;DB_CONNECTION_PROPERTIES=User;DATABASE=dsfunc;USER=sde;VERSION=sde.DEFAULT;AUTHENTICATION_MODE=DBMS"
  }
}

ds.update(pro2)

Related Information

Last Published: 10/14/2020

Article ID: 000022551

Software: ArcGIS API for Python 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6, 1.5.3, 1.5.2, 1.5.1, 1.5, 1.4.1, 1.4, 1.3, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.0.1, 1.0 ArcGIS Data Store 10.8.1, 10.8, 10.7.1, 10.7, 10.6.1, 10.6