Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a Python script that I use to publish ArcGIS 10.0 Geoprocessing Services I have some code:

arcpy.AddMessage("If process hangs here, check for ArcSDE connections issue by trying to open " + mapFile + " in ArcMap")
mxd = arcpy.mapping.MapDocument(mapFile)

The reason I have it is that from time to time the maximum number of SDE Connections that the server can support may have been exceeded.

Before I hit this I would like to have ArcPy test for:

  1. Whether the SDE Connection can be reached at all?
  2. Whether the SDE Connection is to an ArcSDE which is responding within a reasonable time?

Does ArcPy have any means of testing SDE connections before trying to use them?

share|improve this question
up vote 3 down vote accepted

Yes, you can do something like:

      if arcpy.Exists(PropertyTax_Parcels):
         arcpy.AddMessage("Checking core Layer found? Yes and online")
      raise sys.exit("")

You just define it as a static layer in your SDE and if so it can continue; other wise you else out of the script. I do this in many places and will actually log and fire SMTP messages if my connections are lost in core apps.

share|improve this answer
Thanks @D.E.Wright - expect to see me accept your answer as soon as I have had a chance to test "breaking" the SDE connection and seeing how well it handles that condition using your code snippet. – PolyGeo Sep 16 '11 at 6:44
Key is just having the layer there that you want to check; you can't just check for a connection; but being able to connect to the layer gives you a status. Very crude; but that is all we really have in the limited scope. – D.E.Wright Sep 16 '11 at 19:56

Your Answer


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.