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...