Hi All,
I am trying to use arcpy on ArcCatalog 10.2.1 to delete some version on our sql database. when I use the function arcpy.DeleteVersion_management(connection, version.name), i get an error "ERROR 000301: The workspace is of the wrong type". The connection is to a .sde file and the user has permission to delete all versions.
Thank you for your help
Below is my script:
arcpy.env.Workspace = r'C:\Users\JBurgos\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\ArcGIS to BELNetwork.sde'
defaultVersion = "sde.DEFAULT"
connection = arcpy.env.Workspace
versionName = "WR456_DN560"
arcpy.ClearWorkspaceCache_management()
# Execute DeleteVersion
for version in arcpy.da.ListVersions(connection):
try:
print "Found - {0}".format(version.name.split(chr(34) + ".")[1])
currentversion = format(version.name.split(chr(34) + ".")[1])
except:
try:
print "Found - {0}".format(version.name.split(".")[1])
currentversion = format(version.name.split(".")[1])
except:
print "Found - {0}".format(version.name.split(".")[0])
currentversion = format(version.name.split(".")[0])
if currentversion == versionName:
print("Attempting to Delete version {0}".format(version.name))
arcpy.DeleteVersion_management(connection, version.name)
print("Deleted version {0}".format(version.name)) Print ("Done")
Wang, could you format your code, there appears to be indentation errors that may be real or due to copying, it is hard to tell
/blogs/dan_patterson/2016/08/14/script-formatting
And even if you manage to get to the end this line will fail
Print ("Done")
because you need lowercase print
Hi Dan,
Please find the indented codes below. Thank you in advance.
import arcpy
arcpy.env.Workspace = "Database Connections/ArcFM Database.sde"
defaultVersion = "sde.DEFAULT"
connection = arcpy.env.Workspace
versionName = "WR456_DN560"
arcpy.ClearWorkspaceCache_management()
# Execute DeleteVersion
for version in arcpy.da.ListVersions(connection):
try:
print "Found - {0}".format(version.name.split(chr(34) + ".")[1])
currentversion = format(version.name.split(chr(34) + ".")[1])
except:
try:
print "Found - {0}".format(version.name.split(".")[1])
currentversion = format(version.name.split(".")[1])
except:
print "Found - {0}".format(version.name.split(".")[0])
currentversion = format(version.name.split(".")[0])
if currentversion == versionName:
print("Attempting to Delete version {0}".format(version.name))
arcpy.DeleteVersion_management(connection, version.name)
print("Deleted version {0}".format(version.name))
print ("Done")
This may be useful:
https://community.esri.com/thread/197831-error-000301-the-workspace-is-of-the-wrong-type
Also, your first try/except block doesn't provide anthing do do as the exception....
Hi Joe,
I have visited this link before and it didn't help. Thank you though for the link.
arcpy.env.Workspace is not the same as arcpy.env.workspace, which is what your code should use. I am guessing you aren't actually setting the workspace so the code errors with a wrong type message.
Hi Joshua,
I have updated 2 lines of codes as below, but still didn't work. I have also pasted the result, which contain the error message, that I got from running the codes.
Previous:
arcpy.env.Workspace = "Database Connections/ArcFM Database.sde"
connection = arcpy.env.Workspace
Updated to:
arcpy.env.workspace = "Database Connections/ArcGIS to BELNetwork.sde"
connection = arcpy.env.workspace
*************************
Result returned:
Found - DEFAULT
Found - Design
Found - Field
Found - Stretlight 5 year plan
Found - Area order Emilio
Found - RHernandez
Found - New BMP Expansion
Found - Emilio Areas Edits
Found - WR455_DN517
Found - WR455_DN519
Found - Emilio st light reduction
Found - WR455_DN520
Found - WR410_DN527
Found - Street Lights addition south
Found - SL Input EQuetzal
Found - Transformer Selection
Found - Placencia Voltage Edits
Found - Corozal edits Emilio
Found - WR470_DN543
Found - WR455_DN521
Found - WR455_DN522
Found - WR477_DN548
Found - WR468_DN549
Found - WR478_DN550
Found - WR479_DN551
Found - Streetlight_Structurerelate
Found - WR468_DN552
Found - WR480_DN553
Found - WR481_DN554
Found - WR483_DN555
Found - WR484_DN556
Found - new version
Found - San Pedro STL Upgrade
Found - test18042018
Found - WR485_DN558
Found - WR456_DN560
Attempting to Delete version "BEL.COM.BZ\JBURGOS".WR456_DN560
Runtime error Traceback (most recent call last): File "<string>", line 23, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 15196, in DeleteVersion raise e ExecuteError: ERROR 000301: The workspace is of the wrong type Failed to execute (DeleteVersion).
**This is the message in the results windows**
Executing: ClearWorkspaceCache #
Start Time: Fri Nov 02 09:36:41 2018
Succeeded at Fri Nov 02 09:36:41 2018 (Elapsed Time: 0.02 seconds)
Executing: DeleteVersion "Database Connections/ArcGIS to BELNetwork.sde" "BEL.COM.BZ\JBURGOS".WR456_DN560
Start Time: Fri Nov 02 09:36:52 2018
ERROR 000301: The workspace is of the wrong type
Failed to execute (DeleteVersion).
Failed at Fri Nov 02 09:36:52 2018 (Elapsed Time: 0.06 seconds)
You need to connect as the SDE user or some other Admin user to delete versions the user in your connection file does not own...
Hi Joe,
I used the SDE connection and I still get the same message.
Take a look at Joe Head last response in https://community.esri.com/thread/197831-error-000301-the-workspace-is-of-the-wrong-type , see if you have a similar situation going on.