Logging into SDE databases in ArcGIS GUI

117 views
Skip to first unread message

ros...@hotmail.com

unread,
Mar 12, 2014, 12:37:27 PM3/12/14
to geop...@googlegroups.com
Hello everyone, just started with BC Gov and I'm fairly new to working with our servers and SDE Database Connections.
 
I am writing a python script that accesses BCGW.sde. Of course, that sde is password protected, so I need to allow the user to be able to enter their login information for the script to run properly.
 
I wrote a simple script to test an issue I am having:
 
import arcpy
from arcpy import env
 
env.workspace = r"Database Connections\BCGW.sde"
 
print "Something"
 
When I run this from an editor (IDLE or ECLIPSE) and when this script gets to the line setting the workspace path (env.workspace), I get the familiar Database Connections popup window prompting me to log into the BCGW database.
 
When I add this script as a tool in the ArcGIS GUI and run, I still get the database connections popup. This time, however, when it comes up I cannot click in the username and password parameters. The ArcGIS GUI seems to stay on top all the time and overrides the database login prompt. So, in other words, I can click on the Database Connection login prompt window, but when I let go of my mouse click, the ArcGIS GUI automatically comes back to the fore front and won't allow me to access the login prompt.
 
Has anyone had experience with this? Is there anyway to fix this? I need the user of my tool to be able to login to the databse to run some reports off of it.
 
if anyone wants to test and see if they get the same behavior, copy and paste my code above into an editor and run. You will see the prompt. Next, try adding the python script to a custom toolbox as a tool. You don't have to set any parameters. Just give it a anme, add the script file and run and see if you get the same behavior.
 
Thanks,
Mike

Lew.Gr...@gov.bc.ca

unread,
Apr 3, 2014, 5:27:33 PM4/3/14
to geop...@googlegroups.com, ros...@hotmail.com
Hi Mike,
 
Usually I just create the warehouse layer as a variable:  
inSdeFeatures = "Database Connections\\wildfire.sde\\SDE.FMLOADER.IN_CURRENT_FIRE_POINTS_SVW"
 
 
But I've used this solution in the past where my password was embedded in the python script but save to my H drive...
 
if __name__ == "__main__":
    sdeBCGW = r"T:\\TempBCGW_ConnectionFile.sde"
    if os.path.exists(sdeBCGW):
        os.remove(sdeBCGW)
    sdeLadder = r"T:\\TempLadder_ConnectionFile.sde"
    if os.path.exists(sdeLadder):
        os.remove(sdeLadder)   
   
    #call sdeConnection.py which has embedded passwords
    execfile(r"H:\!RGC_Admin\Python\sdeConnection.py")
 
 
sdeConnection.py is saved on my H drive, below:
 
# Import ArcPy and os modules
import arcpy, sys, string, urllib, re, time, os
 
if not os.path.exists(sdeLadder):
    #arcpy.CreateArcSDEConnectionFile_management(r"T:\\", "TempLadder_ConnectionFile", "Ladder.idir.bcgov","5151","","OPERATING_SYSTEM_AUTH","","","","SDE.DEFAULT","SAVE_VERSION")
    arcpy.CreateArcSDEConnectionFile_management(r"T:\\", "TempLadder_ConnectionFile", "Ladder.idir.bcgov","5151","","DATABASE_AUTH","idir\lgreentr","<MyPasswordHere>","","SDE.DEFAULT","SAVE_VERSION")   
#arcpy.CreateArcSDEConnectionFile_management(r"T:\\", "TempBCGW_ConnectionFile", "slkux1.env.gov.bc.ca","5153","","DATABASE_AUTH","lgreentr","<MypasswordHere>")
if not os.path.exists(sdeBCGW):
    arcpy.CreateArcSDEConnectionFile_management(r"T:\\", "TempBCGW_ConnectionFile", "slkux1.env.gov.bc.ca","5153","","DATABASE_AUTH","lgreentr","<MyPasswordHere>")
    #arcpy.CreateArcSDEConnectionFile_management(r"T:\\", "TempBCGW_ConnectionFile", "slkux1.env.gov.bc.ca","5153","","OPERATING_SYSTEM_AUTH","","","","SDE.DEFAULT","SAVE_VERSION")
Reply all
Reply to author
Forward
0 new messages