I am publishing a geoprocessing service on ArcGIS Server v10.3.0 that updates data on an ArcSDE Enterprise Geodatabase.

I have the following at the beginning of my script:

arcpy.env.workspace = "Database Connections/[email protected]"

As discussed at Connecting Geoprocessing Service to ArcSDE?, when I publish the script as a geoprocessing service, that line gets changed to:

arcpy.env.workspace = arcpy.env.packageWorkspace

This is all well and good, but arcpy.env.packageWorkspace is simply the v101 folder for this geoprocessing task. It is not the actual .SDE connection file. I can confirm that the .SDE connection file does get moved to the v101 folder, but arcpy.env.packageWorkspace is simply a file path to the v101 folder--not that file.

Because of this, when I call arcpy.ListFeatureClasses() or arcpy.ListDatasets(), an empty list gets returned. From what I can tell this is because the workspace is set to a folder on the server's file system, and not an .SDE file.

How are .py files being re-written when they are published as geoprocessing services? What is the proper syntax to use when setting the workspace so that the published version of the script references an .SDE file and not simply a file folder?

  • Try registering the geodatabase connection the python script is referencing with the server. The server is touchy about that stuff. Also, maybe set the workspace to an input variable that defines the workspace instead of hard coding the path. Jan 3, 2016 at 4:22
  • The database is indeed registered with the server. I would like to avoid having the workspace as an input variable since this will be accessed through Web AppBuilder and the workspace isn't an intuitive variable for a user to provide. But I will try that for debugging purposes and report back.
    – George
    Jan 3, 2016 at 4:31

1 Answer 1


Try this...change arcpy.env.workspace = "Database Connections/[email protected]" to

import os myfolder = 'c:\mysdefiles' sdePath = os.path.join(myfolder, '[email protected]') arcpy.env.workspace = sdePath

Then, you obviously need to copy the sde file from the database connections node to the folder you've referenced in the myfolder variable. Also register that folder with the servers data store.

  • Thanks @khibma--I'll give this a try. What is the purpose of Server automatically copying the .SDE file to the packageWorkspace during publishing if this is the correct way to handle these cases?
    – George
    Jan 3, 2016 at 19:23
  • I said register that folder, actually you don't have too. If you do register it, server won't copy the contents of the folder. If you don't register it, the contents (sde file) get moved. That's the nature of the publishing process.
    – KHibma
    Jan 3, 2016 at 20:26
  • When I had arcpy.env.workspace = "Database Connections/[email protected]" earlier, that database connection was registered with the server. In spite of this, an .SDE file was still being copied to the v101 folder for the geoprocessing service. Should this be happening?
    – George
    Jan 3, 2016 at 20:32
  • Yes, generally speaking, the sde file is always copied to the server. Your case here is sort of between two workflows case. Directly using the sde file as input to the env causes the confusion. So building a path to the sde treats it more like data than a workspace
    – KHibma
    Jan 3, 2016 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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