xyknewtry

Proper way to delete a feature class from Personal Geodatabase?

Discussion created by xyknewtry on Jun 15, 2012
Latest reply on Jun 20, 2012 by xyknewtry
Hello,

I'm working on an Addin where I need to check if the user specified output feature class already exists. If it does then it needs to be deleted first before the new one is created.

...
IFeatureClass outputFeatureClass=null;
IWorkspaceFactory2 wsFactory = new AccessWorkspaceFactory() as IWorkspaceFactory2;
                string fullDatasetName=gxDialog.FinalLocation.FullName.Replace(gxDialog.FinalLocation.Name,"");
                fullDatasetName = fullDatasetName.Substring(0, fullDatasetName.Length - 1);
                IFeatureWorkspace fWorkspace = wsFactory.OpenFromFile(fullDatasetName,0) as IFeatureWorkspace;
                IFeatureDataset fDataset = fWorkspace.OpenFeatureDataset(gxDialog.FinalLocation.Name);
                IFeatureClassContainer fcContainer = fDataset as IFeatureClassContainer;
try
                {
                        outputFeatureClass = fcContainer.get_ClassByName(gxDialog.Name);
                        IDataset dataset = outputFeatureClass as IDataset;
                        dataset.Delete();
                }
                catch (System.Exception ex)
                {
                        MessageBox.Show(ex.Message);
                }
              
                try
                {
                    outputFeatureClass = fDataset.CreateFeatureClass(
                        gxDialog.Name, fields, null, null, esriFeatureType.esriFTSimple, shapeFieldName, "");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

This logic works fine if the target database is a File Geodatabase (of course the workspacefactory in that case is different). However it doesn't work with a Personal Geodatabase. If the output feature class already exists, this is the exception message I'm getting on the delete operation ("tmp" is the name of the output feature class):
"
The database engine could not lock table 'tmp_SHAPE_Index' because it is already in use by another person or process.
"

So I'm guessing the delete method on the IDataset interface doesn't do the job for a FC in Personal Geodatabase? What is the best way to delete a Personal Geodatabase feacture class? Thank you!

Yukun

Outcomes