HOW TO
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.
import arcpy from arcgis.gis import GIS
gis = GIS("https://machine_name.domain:7443/arcgis/home","username", "password", verify_cert=False) print("connected")
dstores = server1.datastores.list() dstores
arcpy.CreateDatabaseConnection_management("C:\\MyProject", "test.sde", "SQL_SERVER", "SQL Server", "OPERATING_SYSTEM_AUTH")
server1.datastores.generate_connection_string(r"C:\\MyProject\test.sde")
ds = dstores[N] ds
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>" } }
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
Get help from ArcGIS experts
Download the Esri Support App