Trying to run a Python script on an ArcGIS Server that has Desktop installed.

07-28-2017 11:46 AM
New Contributor III

I have ArcDesktop 10.5 installed on an ArcGIS for Server 10.5 virtual machine (AWS).  I am trying to develop a script to be run automatically that will provide me with Statistics Analysis information.  I originally created the script on my laptop using local SDE connections and folders without any issues but when I copy it and try to modify it on the ArcGIS Server machine, it doesn't work.   When I try to run the Python script on the ArcGIS Server machine, I get that the input table does not exist or not supported. Therefore, I confirmed that I could run the Statistics Analysis tool in ArcCatalog and ArcMap on the ArcGIS Server. I have copied the Python snippet from the ArcGIS Server machine version of ArcCatalog and ArcMap copying the database connection information from the database connection properties window in ArcCatalog and it still give me the same error.  I am wondering if Python is getting confused with the 64-bit Oracle client which would not be defined from ArcDesktop software (32-bit Oracle client is used).  

I have commented out the variable that contained the path copied from ArcCatalog and used arcpy.CreateDatabaseConnection_management to create the same SDE connection but it still does not work and I even stored the sde connection file in the folder with the script.  I have tried defining the workspace using the Python created SDE connection and one specific feature class but I get the "RuntimeError: Object: Error in accessing environment <workspace>" error.  

Has anybody had any success in running automated scripts on an ArcGIS Server machine that uses ArcDesktop geoprocessing tools accessing an SDE connection from Python?  I would greatly appreciate any assistance with this issue.  Thank  you!!  PS - Not sure if it matters but I am using Oracle 11g as my enterprise database.

0 Kudos
4 Replies
New Contributor III

Do I need to install ArcSDE 10.2.2 in order to run Python scripts on an AWS instance running ArcGIS for Server 10.5.1 that are attempting to connect to Oracle 11g database?  I have Desktop installed and have tried to use the .sde connection files created within ArcCatalog but I am unable to list feature classes in the Oracle database.  I have created sde connections within the Python script and then copied them to the folder for ArcCatalog and they showed up and worked when I started ArcCatalog, so I know the sde files are being created properly.  But, I am not able to get Python to connect to the Oracle database.

0 Kudos
Esri Esteemed Contributor

No, you never need to install any ArcGIS 10.2.x product for ArcGIS 10.5.x access to anything.

Keep in mind that Desktop is 32-bit while Server is 64-bit, so you must have 64-bit Oracle libraries installed for successful Server connection.

- V

New Contributor III

Vince I have both 64-bit and 32-bit Oracle clients installed on the map server (since it was an AWS build, the 64-bit was already installed).  I confirmed with my Oracle DBA that I am not getting any connection to the database.  Below is just a portion of my script (although it lost the formatting).  I have confirmed that if I copy the SDE file that is created in Python to the appropriate folder, I can open it with ArcCatalog.

import arcpy, os

from arcpy import env

arcpy.env.overwriteOutput = True

# Set local variables
gdb_in = r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\Real_Property.sde" #path to input geodatabase
gdb_in2 = r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\GIS_Support_v1_1_testZ.sde" #path to input geodatabase
Database_Connections = "C:\\Users\\Administrator\\AppData\\Roaming\\ESRI\\Desktop10.5\\ArcCatalog"
script_path = sys.path[0]
out_folder_path = script_path
out_name_GIS = r"GIS_Support_v1_1_testZ.sde"
out_name_RP = r"Real_Property.sde"
gdb_out = r"D:\data\stats" #path to output geodatabase
d = str("%Y%m%d"))
out_name = "qaqc_"+d+".gdb"
feature_classes = []

sde_GIS = arcpy.CreateDatabaseConnection_management(out_folder_path,
"ORACLE", # Database platform
"sde:oracle11g:ztracs", # "ztracs" 32-bit instance name 64-bit instance name = "testz_tracs"
"DATABASE_AUTH", # account authentication type
"GIS_Support_v1_1", # username
"Hjs#Jl_3234jksdf#") # password

gdb_out_ds = arcpy.CreateFileGDB_management(gdb_out, out_name)
output = str(gdb_out_ds)
fc = str(sde_GIS)+"\State_Polygons"
fc2 = r"GIS_Support_v1_1.State_Polygons"

# Feature dataset in GIS_Support_v1_1 schema

print script_path
#Path to SDE using script path variable
sdeconn = os.path.join(str(script_path), str(sde_GIS))
print sdeconn
#Path to feature class
polfc = os.path.join(sdeconn, fc2)
print polfc

ws = arcpy.env.workspace = sdeconn

print ws

if arcpy.Exists(ws):

fcList = arcpy.ListFeatureClasses()

for fc in fcList:
print fc

print "Made it to here"

arcpy.Statistics_analysis(str(sde_GIS)+"\\"+fc2, output+"\\"+fc2, "OBJECTID FIRST", "STATE_ABBREV")


The results are:

Made it to here

Traceback (most recent call last):
File "D:\scripts\", line 64, in <module>
arcpy.Statistics_analysis(str(sde_GIS)+"\\"+fc2, output+"\\"+fc2, "OBJECTID FIRST", "STATE_ABBREV")
File "C:\Program Files\ArcGIS\Server\ArcPy\arcpy\", line 1338, in Statistics
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset D:\scripts\GIS_Support_v1_1_testZ.sde\GIS_Support_v1_1.State_Polygons does not exist or is not supported
Failed to execute (Statistics).

0 Kudos
New Contributor III

I actually found the answer to my issue in "FAQ: Why do Python scripts fail on a machine with both ArcGIS for Server and Desktop installed?"  The default Python version was the 64-bit version but since I was using Desktop tools and I needed to be using the 32-bit Python version.