I am a beginner with Python and ArcPy.
I am trying to write a Python script that will overwrite the viewer copy of our data with the most recent editor copy. Here is the code I am running through the Python window:
import arcpy
import os
arcpy.AcceptConnections(TargetDB, False)
time.sleep(1)
arcpy.DisconnectUser(TargetDB, "ALL")
time.sleep(1)
arcpy.conversion.FeatureClassToFeatureClass(EditorFC, OldDataPath, "TaxParcel")
time.sleep(1)
arcpy.AcceptConnections(TargetDB, True)
Upon running that, however, I get the following error message:
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 3204, in FeatureClassToFeatureClass
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\conversion.py", line 3201, in FeatureClassToFeatureClass
retval = convertArcObjectToPythonObject(gp.FeatureClassToFeatureClass_conversion(*gp_fixargs((in_features, out_path, out_name, where_clause, field_mapping, config_keyword), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000601: Cannot delete C:\Users\GISuser\AppData\Roaming\Esri\ArcGISPro\Favorites\OCGIS21 - Vector - GISuser.sde\OCGIS21_Vector.DBO.ParcelPublishing\OCGIS21_Vector.DBO.TaxParcel. May be locked by another application.
Failed to execute (FeatureClassToFeatureClass).
What am I doing wrong?
Once I get this straightened out, my plan is to export this as a Python file to run through windows task scheduler on a nightly basis.
arcpy.ListUsers(TargetDB)
after runningarcpy.DisconnectUser(TargetDB, "ALL")
, it will list in a tuple what users were not disconnected. I've had to usetime.sleep()
before as well for overwriting items, but typically usetime.sleep(5)
. If you continue to have users after running DisconnectUser, then you may not be using an SDE connection with administrative rights on the SDE. Also, you may want to consider enabling overwrites by setting the environment variable to allow it.arcpy.env.overwriteOutput = True