Calling arcpy.da.Editor from geoprocessing service in webapp

630
7
Jump to solution
05-20-2021 06:55 PM
_watcher_
New Contributor II

I’m a newbie so please excuse a dumb question; I’m just finding the documentation rather confusing.

Can I use arcpy.da.Editor in a geoprocessing service called by a web app? If I can, how do I determine what the workspace is?

This is the code I’m attempting to use:

edit = arcpy.da.Editor(arcpy.env.workspace)

edit.startEditing(False, False)

edit.startOperation()

// my code here

edit.stopOperation()

edit.stopEditing(True)

The full story is there’s an existing ArcMap addin with a toolbox module. I’m attempting to publish the toolbox as a set of geoprocessing services, which will be called from geoprocessing widgets in a new web app (created with web appbuilder). At the moment, calling any of the geoprocessing service is failing with the error “cannot open workspace”.

It seems logical that there might be some extra set up required before trying to get the workspace; this is a web app, not ArcMap (when used in ArcMap, the workspace comes from a settings file). But I’m not sure if it’s even possible to do what the code is trying to do. Because this is an existing (unfamiliar!) codebase, I’m also trying to minimise the changes and identify if the code needs to diverge in order to support the web app.

0 Kudos
1 Solution

Accepted Solutions
_watcher_
New Contributor II

Ok, so according to this question Why would a python script run fine from within ArcMap but not as a geoprocessing service?  I need to do the following:

arcpy.env.workspace = os.path.dirname(r"//[servername]/connections/dbconnection.sde")

This call cuts off the dbconnection.sde part of the path. Not sure why this fixes the problem, but I'm now onto a different error in a different part of the code, so that's one step further than I was before.

View solution in original post

0 Kudos
7 Replies
DanPatterson
MVP Esteemed Contributor

The workspace would be a geodatabase or a folder (for shapefies).

Editor—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
_watcher_
New Contributor II

Thanks Dan!

Something like this perhaps?

arcpy.env.workspace = r"//[servername]/connections/dbconnection.sde"

0 Kudos
BlakeTerhune
MVP Regular Contributor

It would be arcpy.env.workspace = r"\\[servername]\connections\dbconnection.sde"

If you really are going to a database connected saved on a different server, you'll have to include a drive letter like arcpy.env.workspace = r"\\[servername]\c$\connections\dbconnection.sde"

0 Kudos
_watcher_
New Contributor II

Thanks Blake. The connection files sit on a shared folder, so there should be no need for the drive letter, but did I try your both of your suggestions (without success)

0 Kudos
BlakeTerhune
MVP Regular Contributor

I have to ask, why wouldn't you edit a feature service instead of trying to use Editor?

0 Kudos
_watcher_
New Contributor II

There's an existing toolbox in use in ArcMap containing the functionality that is tested and works. All that's wanted is to provide an additional access point via web app. 

0 Kudos
_watcher_
New Contributor II

Ok, so according to this question Why would a python script run fine from within ArcMap but not as a geoprocessing service?  I need to do the following:

arcpy.env.workspace = os.path.dirname(r"//[servername]/connections/dbconnection.sde")

This call cuts off the dbconnection.sde part of the path. Not sure why this fixes the problem, but I'm now onto a different error in a different part of the code, so that's one step further than I was before.

0 Kudos