[GIS] Change sde connection parameters with ArcPy

arcmaparcpyenterprise-geodatabaseesri-geodatabase

I know you can create a database connection with Arcpy using the CreateDatabaseConnection_management function. I am wondering if anyone knows a way in which to change the parameters of that file.

For instance, say you want to use the same .sde connection file, however you want to log into a different database, or connect with a different user.

Essentially is there a way to access the properties of it as if you just right click on the connection in catalog and select connection properties.

I'd rather have my script modify the settings than delete that sde file and recreate it with the same name but different parameters.

Best Answer

You could have all of your connections previously established. When you want to run the script as "SDE" you could then establish your workspace using the connection file as "SDE". If you wanted to run the script as "DATA" you could then establish your workspace using the connection file as "DATA". That would be an effective way to utilize different connections with different credentials. I dont think it is possible to just connect through arcpy. The module needs something to use during the process, i.e. a connection file.

For example:

import arcpy
from arcpy import env
env.workspace = r'PATH TO CONNECTION FILE FOR SDE'

Run your script

import arcpy
from arcpy import env
env.workspace = r'PATH TO CONNECTION FILE FOR DATA'

Run the same script