Trouble Running Geodatabase Compress as Python Script

1241
5
05-27-2020 10:32 AM
PatrickMcKinney1
Occasional Contributor III

I have had a Python 2/ArcMap script to compress enterprise geodatabases.  The script has worked fine for a while now.  I recently converted the script to Python 3/ArcGIS Pro. Now, I keep getting the same error (see below).  I've tried referencing the sde connection files using os.path.join and as a single variable (drive/letter/file). I'm looping through a list of geodatabases.

Error: Failed to execute. Parameters are not valid.
ERROR 000837: The workspace is not the correct workspace type.
Failed to execute (Compress).

FILE: compress_geodatabases.py, LINE: 41

"arcpy.management.Compress(gdb[0])": Failed to execute. Parameters are not valid.
ERROR 000837: The workspace is not the correct workspace type.
Failed to execute (Compress).

Error compressing CCGIS.sde

 

# compress geodatabases
    for gdb in geodatabases:
        try:
            # start time for compress
            start_time_compress = time.perf_counter()
            # compress tool
            arcpy.management.Compress(gdb[0])
            # end time for compress
            end_time_compress = time.perf_counter()
            # elapsed time compress
            elapsed_time_compress = end_time_compress - start_time_compress
            # round elapsed time
            elapsed_time_compress_rounded = round(elapsed_time_compress, 2)
            # add message
            log_message += '\nCompressed {} in {}-seconds\n'.format(gdb[1], elapsed_time_compress_rounded)
        except EnvironmentError as e:
            log_message += print_errors.print_exception(e)
            log_message += '\nError compressing {}\n'.format(gdb[1])
        except Exception as e:
            log_message += print_errors.print_exception(e)
            log_message += '\nError compressing {}\n'.format(gdb[1])
    # end for in
5 Replies
JoeBorgione
MVP Emeritus

The script shown only goes to line 22; which one refers to line 41?

I used the ESRI example to to that maintenance routine, and as I recall, there was something iffy about it either with the 64 bit python and/or python 3.x.  I'll ping my former co-workers and ask them about it...

That should just about do it....
0 Kudos
RandyBurton
MVP Alum

Assuming that the error on line 41 referrers to line 7 in your snippet, you might use a print statement to see what the variable gdb[0] is referencing.  I also notice that later you are referencing gdb[1] for messaging which is also puzzling.  Since gdb appears to be a tuple/list, you might try a print statement just to verify that it is what is expected.

PatrickMcKinney1
Occasional Contributor III

It turns out I needed a newer Microsoft SQL server driver installed on the server running the script. gdb[0] was a sde connection file. gdb[1] was a common name for the database.

JoeBorgione
MVP Emeritus

Love those simple solutions!

That should just about do it....
0 Kudos
Kara_Shindle
Occasional Contributor III

I am currently running into this.  I ran into it after converting to Python 3 on my old server.  Just moved to an entirely new set of servers, and I'm having issues getting my admin script to run on the new server.  Was working Friday, walked in this morning to see that workspace error - grrr!  

0 Kudos