I have built an ArcGIS script tool that requires a connection to an external SDE geodatabase. When the script starts, it must first connect to that external Oracle database via the "Database Connection" window, which pops up briefly, but gets "grayed out" as soon as you try to fill in the credentials:

The database connection window

I have checked the "Always run in foreground" option for the script tool, but this doesn't fix the problem.

Any suggestions to fix this, either via the script tool properties or in the script itself?

Here are the relevant sections of code:

arcpy.env.workspace = wrkSpcBCGW

#create variables for SDE Features Classes:
vri = r"Database Connections\BCGW.sde\WHSE_FOREST_VEGETATION.VEG_COMP_LYR_R1_POLY"
  • please post your code. I have used script tools with enterprise connections, but I would hard code the connection string in from the database connections folder connection file. – atxgis May 7 '18 at 18:08
  • Code is now included. I don't want to hardcode in the username and password as the script should be available to multiple users with various logins. The important thing is to ensure the Database Connections window stays in the foreground; I don't know why ESRI keeps graying it out as soon as you click on it. – grego May 7 '18 at 18:51
  • I dont know, the tool that I created used a generic connection file in Database Connections so that no one had to log in. The connection UI never appeared, the connections were just referenced in the script. Actually I tried hardcoding the user's connection file names and it didnt work, so I let them use the owner/service account connection file to use the script. Not ideal in most situations but thats my experience. – atxgis May 7 '18 at 20:32

A couple of options I'd try - unfortunately I don't have a GIS server to test on:

  1. Add parameters for Username and Password to the script tool dialog and pass those to the script to use/create a connection. This is probably not overly secure as it probably will pass the password as plain text.

  2. Add a parameter for the user to pass their own database connection from ArcCatalog to the script tool, and then connect using that connection. This would be much more secure than the one above.

  3. Another option would be to have your script create a new connection using the user's username and password, and the "Encrypted String" parameter data type and the "Create Database Connection" tool. Then run your script and have the temporary connection file deleted on completion. See KHibma's answer to Handling user password input in ArcPy scripts? This option may be a decent compromise of the two above.

    enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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