AnsweredAssumed Answered

RuntimeError: cannot open workspace

Question asked by Ernestocd on Apr 4, 2016
Latest reply on Apr 6, 2016 by GSCUser85

Purpose: Edit a versioned feature class within a Feature dataset in order to calculate a field

 

I have a field called Date to store the date of the inspection (data type: date)

 

I have another field called Time_Diff (data type: Long). This field is the one that will be used to calculate the time difference between system date and the date recorded in the Date field.

 

The script keeps failing due to the following runtime error: RuntimeError: cannot open workspace

Any assistance will be greatly appreciated.

 

# Import arcpy module
import arcpy


# Local variables:
Input_MapChangeRequest = "Database Connections\\GISHW.sde\\gishw.PU.HW_FieldCollection\\gishw.PU.MapChangeRequest"
MapChangeRequest_Layer = "MapChangeRequest_Layer"
MapChangeRequest_layer2 = MapChangeRequest_Layer
MapChangeRequest_Layer__3_ = MapChangeRequest_layer2

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Input_MapChangeRequest, MapChangeRequest_Layer, "", "", "OBJECTID OBJECTID VISIBLE NONE;UTILITY UTILITY VISIBLE NONE;ISSUE ISSUE VISIBLE NONE;ASSET ASSET VISIBLE NONE;CRITICAL CRITICAL VISIBLE NONE;NOTES NOTES VISIBLE NONE;STATUS STATUS VISIBLE NONE;REPORTER REPORTER VISIBLE NONE;DATE DATE VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;created_user created_user VISIBLE NONE;created_date created_date VISIBLE NONE;last_edited_user last_edited_user VISIBLE NONE;last_edited_date last_edited_date VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;Time_Diff Time_Diff VISIBLE NONE")

# Process: Change Version
arcpy.ChangeVersion_management(MapChangeRequest_Layer, "TRANSACTIONAL", "ARCGIS_SERVER.PU_web_editing", "")

# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(MapChangeRequest_Layer)

# Edit session is started without an undo/redo stack for versioned data
edit.startEditing(True)

# Start an edit operation
edit.startOperation()

# Process: Calculate Field
arcpy.CalculateField_management(MapChangeRequest_layer2, "Time_Diff", "(datetime.datetime.now() - arcpy.time.ParseDateTimeString( !DATE! )).days", "PYTHON_9.3", "")

# Stop the edit operation.
edit.stopOperation()

# Stop the edit session and save the changes
edit.stopEditing(True)

Outcomes