HOW TO

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

Last Published: July 27, 2022

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.
import arcpy
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 .sde file to connect to the database. Refer to ArcGIS Pro: Create Database Connection (Data Management) for more information.
arcpy.CreateDatabaseConnection_management("C:\\MyProject", "test.sde", "SQL_SERVER", "SQL Server", "OPERATING_SYSTEM_AUTH")
  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:\\MyProject\test.sde")
Sample result of connection string for ArcGIS Data Store
  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

arcpy.CreateDatabaseConnection_management("C:\Users\user\Desktop\Test", "test.sde", "SQL_SERVER", "SQL Server", "OPERATING_SYSTEM_AUTH")
 
server1.datastores.generate_connection_string(r"C:\Users\user\Desktop\Test\test.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)

Article ID: 000022551

Software:
  • ArcGIS Data Store
  • ArcGIS API for Python 1 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options