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/TestDatabase@hq-gissql01.sde"
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?
Answer
Try this...change arcpy.env.workspace = "Database Connections/TestDatabase@hq-gissql01.sde"
to
import os myfolder = 'c:\mysdefiles' sdePath = os.path.join(myfolder, 'TestDatabase@hq-gissql01.sde') 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.
No comments:
Post a Comment