4

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")

    Try
        schemaLock = CType(feature, ISchemaLock)

        schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock)
        classSchemaEdit = CType(feature, IClassSchemaEdit)

        classSchemaEdit.AlterDomain("FieldName", Nothing)
    Finally
        If (Not schemaLock Is Nothing) Then
            schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock)
        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.

5
  • Just an idea, you could use the geoprocessor to call the existing geoprocessing tools to remove association and then delete?
    – Hornbydd
    Commented Sep 10, 2015 at 21:19
  • I did try the "Remove Domain From Field", but it crash with the 999999 error.
    – Stephan
    Commented Sep 10, 2015 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? Commented Sep 10, 2015 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.. Commented Sep 10, 2015 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
    Commented Sep 11, 2015 at 7:04

2 Answers 2

1

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.

1
  • 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)? Commented Sep 16, 2015 at 2:12
0

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"
FROM dbo.GDB_ITEMS AS items INNER JOIN dbo.GDB_ITEMTYPES AS itemtypes
ON items.Type = itemtypes.UUID
WHERE itemtypes.Name IN ('Coded Value Domain', 'Range Domain')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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