Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am writing a script that accesses multiple sde Database connections. I have set the script to include accessing the environment workspace:

import arcpy

arcpy.GetParameterAsText(0)
arcpy.GetParameterAsText(1)

arcpy.env.workspace = r"Database Connections\somedb.sde"

do some python stuff...

arcpy.env.workspace = r"Database Connections\someOtherdb.sde"

So, I open then tool, enter my parameters and run it. When it gets to setting the workspace, I get the regular popup window to prompt me to enter my username and password to the sde database.

The problem I have it that the tool GUI runs on top of the popup. Any time I try to click on the popup window to enter my username and password, the GUI automatically pops on top again and I can't type anything.

Is there any way for me to build the GUI so that I can enter my username and password aside from using the arcpy.CreateArcSDEConnectionFile_management function? My connection files already exist, so I don't need to create new ones. I just need to log in to it.

share|improve this question

2 Answers 2

Why not have the user set the 2 workspaces? And then in the tool parameters set them to Database connnections? So, like this:

import arcpy

workspace1 = arcpy.GetParameterAsText(0)
workspace2 = arcpy.GetParameterAsText(1)

arcpy.env.workspace = workspace1

do some python stuff...

arcpy.env.workspace = workspace2

do some more python stuff...

Or are you not saving your login information inside the connection file?

share|improve this answer
    
Hey, thanks for the reply. The problem is that this method still requires the Database Connections prompt to login your username and password. When the prompt pops up, I try to click in the window to type something, but the ArcGIS GUI automatically pops back on top and becomes the selectable window which prevents me from typing anything into the Connections prompt. –  Mike Mar 11 at 15:33
    
But are you purposefully not saving the login information inside the connection file when it was created? Because if you save the login credentials within the connection file it won't prompt you. –  ian Mar 11 at 15:35
    
Are you assuming that I am using the arcpy.CreateArcSDEConnectionFile_management function? As I mentioned above, i am trying to avoid using that. I have existing DB connections I want to access. I do not want to create new ones if I can avoid it. I haven't found anything in the arcgpy package aside from that function that allows you to connect to existing db connections.... –  Mike Mar 11 at 16:36
    
Well then I don't understand why what you have above doesn't work? arcpy.env.workspace = r"Database Connections\somedb.sde". If you have somedb.sde in your ArcCatalog Database Connections, it should just connect to it UNLESS you don't have your login information saved. Which is why I asked if you are purposefully not saving the login information. –  ian Mar 11 at 16:41
    
There's a few issues around the user saving this information. The organization I work for doesn't like it when they do and we're working off a terminal server for our Desktop application. I find that when I try to save this information, there are times when I log our of the terminal and log back in, it chooses one of 6 servers to work from which seems to erase the login information. Somehow I have to resolve the log in from the GUI or script. –  Mike Mar 11 at 18:02

After testing I found a solution that is working for now. I just went into the validator class and set the workspace environment for both database connections to initiate on tool startup. Now, when I open the tool, I get the Database Connection login prompt to popup twice (one for each DB connection) and I can enter my login information.

Ideally though, I would like to build my ArcGIS GUI to include a string parameter for the username and an encrypted string parameter to accept the password which I would pass along to the connection file prompt. If I find a solution, I will post an answer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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