4

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.

2
  • For different users and databases you create a separate sde file. If you use Windows authentication, you don't have to worry about users - just one sde file per database. BTW, I don't think you can modify an existing sde file.
    – Matej
    Commented Oct 20, 2014 at 21:35
  • Yeah I get that. I have a script that looks in a specific directory for an sde connection file. I guess maybe most important would be if I could change the user and the version that it uses. The process itself will create a version off of another version. So instead of conn.sde conn1.sde conn2.sde What I'm hoping I can do is just have it use conn.sde and change its parameters. I guess I could just delete it and recreate it, but I'm not sure how efficient it would be to delete it and re make it each time
    – branchini
    Commented Oct 20, 2014 at 21:50

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.