Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an application written in Java which uses ArcObjects 9.3. The application accesses a file GeoDatabase. The application produces output in the GeoDatabase that will be accessed by ArcMap. The problem is that ArcMap can't access the file GeoDatabase because my application still has locks on it. The only workaround I have is to close my application, which removes all the locks. But there's got to be a better way than that. Does anyone have a solution for freeing up these locks?

FileGDBWorkspaceFactory fileGDBWF;
fileGDBWF = new FileGDBWorkspaceFactory();
ws = new Workspace(fileGDBWF.openFromFile(workspacePath, 0));
share|improve this question
    
What method are you using to open the tables in the file geodatabase? –  Michael Todd Oct 5 '10 at 16:03
    
The code I used to open the geodatabase looks like this: FileGDBWorkspaceFactory fileGDBWF = new FileGDBWorkspaceFactory(); ws = new Workspace(fileGDBWF.openFromFile(workspacePath, 0)); –  Bill Oct 29 '10 at 14:03
add comment

4 Answers 4

Thanks for you answers. I finally found a solution that worked for me. It involves a class in ArcObjects that I never heard of: Cleaner. It has one method called release which allows you to release the locks on a single ArcObject, which is what I needed to do. It also has some shotgun methods to release all the objects in a thread, or all the objects in the process, but it cautions against using those unless you know that the thread is terminating, or the JVM is shutting down, respectively.

I'm not sure why I needed to manually release the lock, but doing so fixed my problem.

Anyway, here's the link to the JavaDoc for this class:

http://resources.esri.com/help/9.3/arcgisengine/java/api/arcobjects/com/esri/arcgis/system/Cleaner.html

12/30/2011: I found that maintaining a Java HashSet of my ArcObjects made it easy to release any locks that were left behind. There's no penalty for attempting to release a lock that's already been released.

share|improve this answer
add comment

Chad, can you elaborate on your code? How do you process the keys in the keyToDelete list that you have gathered. Also, how did you create kvp (keyValuePair I'm assuming). I've realized that the dbf file is not locked, but a stray .sr.lock file, which itself is locked is what is causing the problem.

share|improve this answer
    
I loop through the keys (which are names of the my file geodatabases) in keysToDelete and remove them from the list of FGDBs to process, as since they have locks on them, I can't do any processing on them. kvp is a dictionary that gets passed into the method. HTH. If the lock files are orphans, you should be able to delete them. It's just hard to know which ones are orphaned - sometimes the filesystem date on the lock file is a clue. –  Chad Cooper Dec 30 '10 at 13:29
add comment

I'd have to think that your application must still be accessing the FGDB somehow. I write to FGDBs programmatically (with .NET though) and don't have to do anything to specifically release my FGDB after I write to it. There really is no way to kill the lock files either. I actually talked to Craig Gillgrass with ESRI about killing lock files and they told me there is no way to do it. Now, that said, I have seen instances where orphaned lock files get left behind, and those usually can be deleted, since they are orphaned. Here's some .NET that I use to check for locks, maybe it will help:

// Before we do anything, run through the FGDB FCs and see if there are locks on any of them
            string gdb = String.Concat(c.fgdbDir, @"\", kvp.Key[0], ".gdb");
            gp.SetEnvironmentValue("workspace", gdb);
            IGpEnumList fcs = gp.ListFeatureClasses("*", "", "");
            string fc = fcs.Next();
            while (fc != "")
            {
                IFeatureClass u = OpenFc(String.Concat(c.fgdbDir, @"\", kvp.Key[0], ".gdb"), fc);
                IDataset ds = (IDataset)u;
                // Get a schemalock on the dataset - this means there is always at least one lock on the FC
                ISchemaLock sl = (ISchemaLock)ds;
                IEnumSchemaLockInfo enumSLI;
                sl.GetCurrentSchemaLocks(out enumSLI);
                int slc = 0;
                ISchemaLockInfo sli = enumSLI.Next();
                while (sli != null)
                {
                    slc++;
                    sli = enumSLI.Next();
                }
                // If schemalock count is >=2, then we have a problem, something else has a lock on the FC
                if (slc >= 2)
                {
                    c.msg = "Schemalock count on FC '" + fc + "' in FGDB '" + kvp.Key[0] + "': " + slc.ToString();
                    Console.WriteLine(c.msg);
                    Messaging.Log(c.msg, c.lw);
                    ISchemaLock sl2 = (ISchemaLock)ds;
                    IEnumSchemaLockInfo enumSLI2;
                    sl2.GetCurrentSchemaLocks(out enumSLI2);
                    ISchemaLockInfo sli2 = enumSLI2.Next();
                    while (sli2 != null)
                    {
                        c.msg = "  Schemalock info: " + sli2.TableName + " : " + sli2.UserName + " : " + sli2.SchemaLockType;
                        Console.WriteLine(c.msg);
                        Messaging.Log(c.msg, c.lw);
                        sli2 = enumSLI2.Next();
                    }
                    keysToDelete.Add(kvp.Key);
                    break;
                }
                fc = fcs.Next();
                // Set schemalock object = null so lock we created goes away, otherwise, there will still be a lock on the FC
                //  and processing will bomb

                System.Runtime.InteropServices.Marshal.ReleaseComObject(ds);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(u);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sl);

            }
share|improve this answer
add comment

Here is the page on Interface ISchemaLock in Java for arcgis 9.3, and the same with code examples for VB and C# (v9.2).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.