Hello Developers,Is it possible to update a coded value domain when the schema has previously been opened and is in an edit session? I keep getting "An exclusive lock could not be acquired" error message. Isn't there a way to release locks, update the domain and return the user to their previous state? If not what does everyone else do for maintaining domains? I have several Type tables that I use as coded value domains. Do I need to write an external application to maintain a sync between the Type tables and the coded value domains? It seems like a catch 22 here. I need an edit session to create the new "Type" but then I must stop editing and release any database locks to update the domain for the new Type. Plus of course I'd like the new Type and it's domain to be immediately available for use.Greg
public static Boolean AddToCVD(IWorkspace ws, string domainName, string sValue, ref int cvdValue)
{
// Get the requested domain from the workspace.
IWorkspaceDomains2 wsd2 = ws as IWorkspaceDomains2;
IDomain domain = wsd2.get_DomainByName(domainName);
ICodedValueDomain pcvd = domain as ICodedValueDomain;
if (pcvd != null)
{
ISchemaLock schemaLock = pcvd as ISchemaLock;
try
{
// Attempt to acquire an exclusive schema lock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
// Add the code and use IWorkspaceDomains2.AlterDomain to store the change.
if (domain.FieldType == esriFieldType.esriFieldTypeString)
pcvd.AddCode(sValue, sValue);
else
pcvd.AddCode(pcvd.CodeCount, sValue);
wsd2.AlterDomain(domain);
return true;
}
catch (COMException comExc)
{
RecordError(comExc,"An exclusive lock could not be acquired");
}
finally
{
// Set the schema lock to a shared lock.
schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
cvdValue = pcvd.CodeCount - 1;// the count was incremented above, return the previous count to get the new value
}
}
return false;
}