arcpy.DeleteVersion_management - ERROR 000301

1076
12
10-31-2018 08:16 PM
WangTsai
New Contributor

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")

0 Kudos
12 Replies
WangTsai
New Contributor

I added the apostrophe to the name but I get the same error.

arcpy.DeleteVersion_management(connection, '\'' + version.name + '\'')

0 Kudos
JoeBorgione
MVP Emeritus

What exactly are you trying to accomplish with this?

That should just about do it....
0 Kudos
WangTsai
New Contributor

To add apostrophe. I have also tried with the combination of double quotation and single quotation: " ' " + version.name + " ' "  Still didn't work.

0 Kudos