Select to view content in your preferred language

how to disconnect user locks from file geodatabase

5242
3
10-05-2016 12:52 PM
BryanPrice
Occasional Contributor

the File Geodatabase is a ArcGIS term which uses a file folder structure to store geo enabled data. For one of my data maintenance nightly process i use python scripting to stop & block connections to my enterprise SQL database by using the commands...

_________________________________________________________________________________
# Set the necessary product code
import arcinfo

# Import arcpy module
import arcpy

# Local variables:
OwnerCurrentYr_sde = "Database Connections\\OwnerCurrentYr.sde"
OwnerCurrentYr_sde__2_ = OwnerCurrentYr_sde
OwnerCurrentYr_sde__3_ = "Database Connections\\OwnerCurrentYr.sde"
OwnerCurrentYr_sde__7_ = OwnerCurrentYr_sde__3_
OwnerCurrentYr_sde__5_ = "Database Connections\\OwnerCurrentYr.sde"
OwnerCurrentYr_sde__6_ = OwnerCurrentYr_sde__5_

# Stop new connections
arcpy.AcceptConnections("Database Connections\\OwnerCurrentYr.sde", False)

# Process: Disconnect all users
arcpy.DisconnectUser("Database Connections\\OwnerCurrentYr.sde", "ALL")


...... i then do other tasks to compress database, rebuild indexes, Analyze datasets and then i allow connections to begin connecting to the SQL database.
# Enable users to begin connections
arcpy.AcceptConnections("Database Connections\\OwnerCurrentYr.sde", True)
_______________________________________________________________________________

The above workflow works great for the SQL connections , but how do i do this for a file geodatabase?

3 Replies
RebeccaStrauch__GISP
MVP Emeritus

Hi Bryan,

I have not been successful in totally disconnecting users from a FGDB, short of maybe a reboot of the fgdb machine.... or maybe somehow blocking access to the folder completely, but even with that, with windows, my guess is permission connections would persist until a reboot or logout/in.

But I am making progress in finding if the fgdb is in used or accessed in anyway. We've had an issue today were an mxd is opening file gdb files, in Windows point-of-view, but is not creating any .lock files.  I was testing for the existence of the .locks before I renamed or deleted a file gdb.  The rename would just fail, but the delete would delete all but about 5 files, but the file gdb would now be corrupt, with an folder with the .gdb extension that could no longer be deleted.  and testing with arcpy.Exists no longer sees the folder as a gdb.  However, those un-deleted files are still open by the user(s)

I can restore the fgdb by copying the files that were deleted from the fgdb file from a backup, but this is an issue.

I've been using the  FSMGMT.MSC and the  NET FILES  windows commands to help find these hidden locks, but so far have only had success running them manually.  I'm trying to figure out how to capture this info in my python script BEFORE attempting the rename.  ....anyone have any ideas?  (not trying to hijack this thread...so will spin off if anyone does).

In the various threads I've seen that talk about the FSMGMT.MSC command, there is a command line that says you can /close the files, but so far, this has not closed connection to the fgdb if they have it open in an mxd for example.

 One issue with trying to run the NET FILES is it needs to be run as an administrator.  I've seen some talk about creating a bat file or using import subprocess to run this, but I haven't figured that out yet, our how to capture or query the output for the fgdb in questions.

Anyway, you are not alone in trying to figure this out.  I

Some links of interest that I've been working thru

https://community.esri.com/thread/53359#comment-265240 

and a stackexchange with the same info  arcgis 10.0 - Problems with a FileGeodatabase locking - Geographic Information Systems Stack Exchang... 

https://wiert.me/2012/12/03/commandline-equivalents-for-fsmgmt-msc-net-share-net-view-net-session-ne... 

BTW- I have several snippets written using various tests, looking for the locks if you are interested.  Once I figure this all out, I hope to summarize and post as a doc.  

by Anonymous User
Not applicable

If you have a solution to share here - that would be fantastic. I have been trying to resolve this issue for some time as well.

MichaelKohler
Frequent Contributor

I know this thread is a few months old but I found a workaround for my issue that might be related. I have a routine that updates crime data each morning by downloading files from a ftp, does some processing and geocoding to update their data. After banging my head against the wall to get them to close out their arcmap and catalog every night, I came up with this solution. I work off a FGDB on my computer that I know wont have a lock on it. Then at the end, I try to delete their FGDB and replace with my version. So I run the script as if the users closed out arcmap/catalog and use a try/catch to look for these errors.

000725: Dataset already exists. 

000601: Cannot delete <value>. May be locked by another application.

000012: <value> already exists.

If I catch any of these, I just copy every file inside the FGDB folder from mine to theirs except the lock caused by my script. Been running for sometime like this with no issues. Below is the tail end of the script where the delete starts and the except is. FYI, notify() is a custom script that sends emails to me so I know what happens as this runs at 5:30 am.

    errMsg = 'Delete DJJ gdb'
    print(errMsg)
    arcpy.Delete_management('{}\\DJJ_Data.gdb'.format(pdfsmain), "")
    
    errMsg = 'copy new DJJ'
    print(errMsg)
    arcpy.Copy_management('{}\\DJJ_Data.gdb'.format(csv_loc), '{}\\DJJ_Data.gdb'.format(pdfsmain), "")
    
    notify("PDA DJJ update complete", subject, from_add, to_add)
    print 'done'   
except Exception:
        e = sys.exc_info()[1]
        if "ERROR 000725:" in e.args[0] or "ERROR 000601:" in e.args[0] or "ERROR 000012:" in e.args[0]:
            print "Error trapped"
            lst = os.listdir('{}\\DJJ_Data.gdb'.format(csv_loc))
            for f in lst:
                print f
                if not "lock" in f:
                    shutil.copy2('{}\\DJJ_Data.gdb\\{}'.format(csv_loc,f),'{}\\DJJ_Data.gdb\\{}'.format(pdfsmain,f))
            print 'copied'
            notify('Copied files because of lock', subject, from_add, to_add)
        else:
            msg = "Update DJJ fGDB failed: %s \n with: %s \n and %s" % (arcpy.GetMessages(2),e,errMsg)
            notify(msg, subject, from_add, to_add)
            print 'failed'
0 Kudos