Select to view content in your preferred language

CreateVersion tool doesn't like my workspace

5610
9
11-02-2010 08:57 AM
DanNarsavage
Frequent Contributor
I've written a Python script that pulls a bunch of feature classes out of SDE into a file GDB on my C: drive, performs a bunch of analysis, then creates a new version on SDE (a child of default), puts the analysis results in the database, reconciles, posts, etc...

This line:
arcpy.CreateVersion_management(DefaultSdeGDB, "sde.DEFAULT", VersionName, "PROTECTED")

used to work fine, but something must have changed somewhere because suddenly the CreateVersion tool fails with the following messages:
arcpy.CreateVersion_management(DefaultSdeGDB, "sde.DEFAULT", VersionName, "PROTECTED")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 9192, in CreateVersion
    raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000837: The workspace is not the correct workspace type.
WARNING 000379: The value may not be valid because of empty domain or does not exist in the domain
Failed to execute (CreateVersion).


The "DefaultSdeGDB" variable is a reference to a connection file in ArcCatalog's "Database Connections" folder, and it works when creating references to feature classes earlier in the script.  And it used to work in this function as well.

This happens regardless of whether I'm pointing at our production database or testing database (but they're on the same machine and they're both still running 9.3 while 10 is on my desktop--but that didn't create a problem earlier).  If I delete all the earlier code from the script and run it again (starting with "CreateVersion..."), it works fine.  With that in mind, I've tried setting the "DefaultSdeGDB" variable to 'None,' waiting five seconds, resetting the variable, and retrying the version creation; but that doesn't work either.

Any other ideas?  Thanks in advance.

Dan
0 Kudos
9 Replies
ChrisSnyder
Honored Contributor
Does it work when you do it manually? There seems to be a lot of bugs in v10 SP0, so it wouldn't suprise me if was ArcGIS itself.

Per the error and warning, are there "invalid" values? Are you sure DefaultSdeGDB points to a .sde file, and are you sure that .sde file exists?
0 Kudos
DanNarsavage
Frequent Contributor
Thanks Chris.  Yes and yes--it works manually and the variable holds a reference to an existing connection file.  I'm kinda thinking the same thing about a bug, but my lack of faith in my own skills prevents me from writing this off until a patch or service pack.  Thanks again!
0 Kudos
ChrisSnyder
Honored Contributor
What is on line 9192 of C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py?
0 Kudos
DanNarsavage
Frequent Contributor
"raise e"

🙂

It's just what's in the "except" statement for when something fails.  Here's the whole function that's in there (but just to be clear, this is ESRI code, not mine):

@gptooldoc('CreateVersion_management', None)
def CreateVersion(in_workspace=None, parent_version=None, version_name=None, access_permission=None):
    """CreateVersion_management(in_workspace, parent_version, version_name, {access_permission})

        Creates a new version in the specified geodatabase.

     INPUTS:
      in_workspace (RemoteDatabase):
          The ArcSDE geodatabase that contains the parent version and will contain the new
          version. The default is to use the workspace defined in the environment
          settings.
      parent_version (String):
          The geodatabase, or version of a geodatabase, on which the new version will be
          based.
      version_name (String):
          The name of the version to be created.
      access_permission {String}:
          The permission access level for the version."""
    try:
        retval = convertArcObjectToPythonObject(gp.CreateVersion_management(*gp_fixargs((in_workspace, parent_version, version_name, access_permission), True)))
        return retval
    except Exception, e:
        raise e


I'm not gonna hunt down what went wrong in the convertArcObjectToPythonObject function.  If there's a problem there then that's certainly an ESRI issue.
0 Kudos
RussellBrennan
Esri Contributor
Dan,

Try running this line right before creating the version.

arcpy.ClearWorkspaceCache_management()


I have seen some cases in my testing where connection properties were cached and caused issues when trying to create new workspaces.

Hope this helps,
0 Kudos
DanNarsavage
Frequent Contributor
That did it (at least in our testing database)!  Thanks Russell!  I've never quite understood what that tool was supposed to accomplish.  Now I know . . . sorta.  😮

Did ESRI do away with the "This post answered my question" thingamajig for these new forums?
0 Kudos
RussellBrennan
Esri Contributor
Glad to hear that helped.

Did ESRI do away with the "This post answered my question" thingamajig for these new forums?


The thingamajig is gone for now. I *think* there are plans to bring it back at some point but am not 100% sure.
0 Kudos
LalitArora1
Emerging Contributor
I'm using ArcGIS V10.0 SP2.
I have used ClearWorkspaceCache_managment tool before CreateVersion.
But I got this error 000837(above mentioned).
0 Kudos
BruceCotton
New Contributor
Hi,

I've finally found a fix to the ERROR 000837 in this context.  I was getting this error when reconciling and posting a number of versions in a loop.  It would work the first time but on the second loop, I get the 000837.

I found that I needed to basically reconnect to SDE on each loop (it appears to disconnect after each Rec and Post), so I use the arcpy.ClearWorkspaceCache_management() to clear the connection and reconnect using a simple function.

# Set up database connection as a repeatable process to prevent connection problems during looping
def connectWorkspace (cw):
    arcpy.env.workspace = originalWksp
    theWS = arcpy.env.workspace
    return theWS

# Set original workspace variable
originalWksp = arcpy.GetParameterAsText(0)

# Then just before each occurance of the "Reconcile and Post" line of code
# Clear connection and reconnect to avoid "ERROR 000837: The workspace is not the correct type"

    arcpy.ClearWorkspaceCache_management ()
    theWS = connectWorkspace (originalWksp)

Cheers,
Bruce

PS Note that the 3 lines of function code need to be indented, but just don't disply that way on this web page.
0 Kudos