Changing text fields length needs an exclusive schema lock on the dataset.
Exclusive schema locks—In contrast to shared schema locks, exclusive
schema locks are controlled by the developer or ArcGIS application,
such as ArcMap or ArcCatalog. An exclusive lock is used to lock a
geodatabase dataset or object from use by others to make the necessary
changes to it. An exclusive lock is promoted from a shared lock and
demoted back to a shared lock when no longer needed. The presence of
additional shared schema locks on a dataset or object prevents an
exclusive schema lock from being applied and precludes the ability to
make changes to the underlying dataset and its schema while it is in
use. Only one exclusive schema lock is allowed per dataset. As opposed
to shared schema locks, exclusive schema locks are not applied or
removed automatically. It is the responsibility of the developer to
apply or remove exclusive schema locks.
So, before running your code, make sure to close your dataset in Arcmap or ArcCatalog.
And then this code:
public void AlterField(IObjectClass objectClass, String fieldName)
// Cast to the ISchemaLock interface.
ISchemaLock schemaLock = (ISchemaLock)objectClass;
// Get an exclusive schema lock on the object class.
// Change the text field length here
catch (Exception e)
// An error was raised; therefore, notify the user.
// Since the Finally block is always called, the exclusive lock is demoted
// to a shared lock after the field is deleted and after an error is raised.