4

I have problem defining arcpy.env.workspace in a separate module when publishing the script as a Geoprocessing Service on arcgis server

For instance:

my main tool script:

from myModule import myTool

workspace = "Database Connections\\[email protected]"
tableName = "DEMMA18.MyTable"

myTool.execute(workspace, tableName)

myModule.myTool:

import arcpy

def execute(workspace, tableName)
    arcpy.env.workspace = workspace
    doSomething(tableName)

def doSomething(tableName)
     with arcpy.da.SearchCursor(tableName, ["OBJECTID"]) as cursor:
            for row in cursor:
                  print(row)

When published to the server, this script will return error : cannot open DEMMA18.MyTable

However, if I put the same code in a single .py file it runs on the server without error. Any Idea what is going wrong?

3
  • Can you please include your entire error message including line numbers and any other python information
    – Midavalo
    Sep 26, 2016 at 17:39
  • How do you specify myTool in myModule? In your tableName what is DEMMA18? What happens if you remove this so tableName = "MyTable"?
    – Midavalo
    Sep 26, 2016 at 17:47
  • 1
    @Midavalo DEMMA18 is the schema name and it takes part of the table name as a convention in the database. The problem is well described by Ben S Nadler answer. I gave an answer on geonet forum: geonet.esri.com/message/… Sep 26, 2016 at 18:03

1 Answer 1

4

Try referencing your full path, not through "database Connections"

The path "Database Connections/..." maps to a user folder. Other users will not have access. Use full paths in scripts.

There is also a issue with the copying enterprise workspace connections during publishing. The workaround is to place the connection file in a registered folder so that your ArcGIS Server has access to it.

4
  • 2
    arcpy.Exists (r"DatabaseConnections\DB.sde") will return false due to requiring space between "Database" and "Connections". It should return true as arcpy.Exists (r"Database Connections\DB.sde"). However if a different user is trying to connect it will fail anyway as Database Connections is stored in user profile and so full path is still recommended. I use a stand-alone folder specifically for all database connections then control permissions so that scripts and other users can still access them if allowed. +1
    – Midavalo
    Sep 26, 2016 at 18:36
  • There is something strange, I have to close/reopen ArcMap between every GP Service I want to publish to arcgis server when I use full path for the arcpy.env.workspace. If not, I got the cannot open table error. Any Idea why? The workspace is a SDE connection file in a location both desktop and server have access. Sep 27, 2016 at 19:35
  • Is the error on the desktop or server logs? Sep 27, 2016 at 19:53
  • It is on the server logs Sep 28, 2016 at 12:02

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.