Determine if SDE Connection is Available

740
3
09-17-2012 07:23 AM
MichaelVolz
Esteemed Contributor
To All SDE Python Users:

Is there a way in python code to determine if an SDE connection is available or not?  I would like a scheduled task to check if SDE is available before attempting to extract data from SDE to a file geodatabase.
Tags (2)
0 Kudos
3 Replies
KevinHibma
Esri Regular Contributor
There might be a more eloquent solution than this....but off the top of my head

r = arcpy.CreateArcSDEConnectionFile_management("c:/temp","sde","ffoooo","411","SQLSERVER","DATABASE_AUTH","sde","*****","SAVE_USERNAME","#","SAVE_VERSION")

msgIndex = 0

while msgIndex < r.messageCount:
    if r.GetSeverity(msgIndex) == 1:
     if '000565' in r.getMessage(msgIndex):
                print "cant connect"
  sys.exit()  
    msgIndex +=1
  
# if you get this far, assumed connection is made...
  
     
   
0 Kudos
AndrewChapkowski
Esri Regular Contributor
You could use the ArcSDESQLExecute command to check your connection:
http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000007z000000
0 Kudos
MichaelVolz
Esteemed Contributor
Is the ArcSDESQLExecute command available in python run in Arc v10.0?

Is there an error message that would arise from this statement in python that can be trapped by a try except statement?
0 Kudos