I need to delete a domain in my database. Since the domain is still associated with a field, I first need to delete the association. After reading the documentation for IWorkspaceDomains.DeleteDomain, it say to use the IClassSchemaEdit.AlterDomain.

So I try using this code to remove the association

    Dim workspaceDomains As IWorkspaceDomains = CType(workspace, IWorkspaceDomains)
    Dim feature As IFeatureClass
    Dim schemaLock As ISchemaLock = Nothing
    Dim classSchemaEdit As IClassSchemaEdit

    feature = CType(workspace, IFeatureWorkspace).OpenFeatureClass("FeatureClassName")

        schemaLock = CType(feature, ISchemaLock)

        classSchemaEdit = CType(feature, IClassSchemaEdit)

        classSchemaEdit.AlterDomain("FieldName", Nothing)
        If (Not schemaLock Is Nothing) Then
        End If
    End Try

When it comes to executing this line classSchemaEdit.AlterDomain("FieldName", Nothing), I get this error :

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in DLLFile.dll

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

So I when back and check the documentation for IClassSchemaEdit.AlterDomain to see how to remove the association, but I found nothing.

What is it that I'm doing wrong. I know I could just copy the data to a new field and delete the original, but this mean that I would have to modify a toolbox, but I would rather avoid it.

  • Just an idea, you could use the geoprocessor to call the existing geoprocessing tools to remove association and then delete? – Hornbydd Sep 10 '15 at 21:19
  • I did try the "Remove Domain From Field", but it crash with the 999999 error. – Stephan Sep 10 '15 at 21:40
  • You are absolutely correct, that should work. The help for IClassSchemaEdit.AlterDomain says To unassociate a domain from a field, supply nothing for the IDomain parameter and your code follows the example; IClassSchemaEdit and ISchemaLock both implements IFeatureClass ... what database is this? pGDB, fGDB or SDE? Is this being run in standalone, ArcMap or ArcCatalog? Is there an FDO_Error number with your HRESULT? that could help narrow it down. Are you sure that nothing else has a lock or is looking at the data and the field exists? – Michael Stimson Sep 10 '15 at 23:32
  • Have you tried using IClassSchemaEdit2 help.arcgis.com/en/sdk/10.0/vba_desktop/componenthelp/… ? perhaps the updated version may be the result of a bugfix... 3 and Ex are not implemented by IFeatureClass; you could cast your feature class to an object class then to IClassSchemaEdit3.. – Michael Stimson Sep 10 '15 at 23:39
  • Do you want to remove the domain from your database? or do you want to remove the domain associate to a certain Field? It is quite different.. – Katah Sep 11 '15 at 7:04

After doing some more test and talking with one of my colleague, we found the problem. Turn out the problem is with the FeactureClass I'm trying to modify. I can't remove any Domain associated with a Field in this FeatureClass.

To correct the problem, we decided to create a new FeatureClass and copy all the data in the new one.

| improve this answer | |
  • That's fairly extreme for such a simple operation... why is it that a domain can't be disassociated from a field? Is it because it came from Oracle and there's some latent restrictions? Is the database compresed (read-only)? – Michael Stimson Sep 16 '15 at 2:12

In order to delete a domain from a field in a table/feature class you must own the domain. Here is a sql query that will list the domain and it's owner. Whomever creates the domain is the domain owner. You can also try IWorkspaceDomain.CanDeleteDomain to test for permission to delete the domain.

SELECT items.Name AS "Domain Name",
 items.Definition.value('(/*/Owner)[1]','nvarchar(max)') AS "Owner"
ON items.Type = itemtypes.UUID
WHERE itemtypes.Name IN ('Coded Value Domain', 'Range Domain')
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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