This document is archived and information here might be outdated.  Recommended version.


Querying workspace properties (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Workspaces > Querying workspace properties

Querying workspace properties


Summary
This topic describes how to retrieve the properties of a workspace, such as whether it supports certain actions or data (for example, archiving or high-precision geometry), the geodatabase release number, the workspace's available configuration keywords, and the type of underlying database management system (DBMS).

In this topic


Workspace properties

Workspace properties are objects that can be used to query a workspace about its capabilities and limitations. The following are the two types of workspace properties:
  • Those that indicate the capabilities of the workspace
  • Those that indicate the capabilities of tables in the workspace
The following table shows a complete list of workspace properties:
Property name
Description
Return type
CanExecuteSQL
Is the ExecuteSQL function supported?
Boolean
CanEdit
Is the workspace editable?
Boolean
IsReadonly
Is the workspace read-only?
Boolean
SupportsQualifiedNames
Does the workspace support qualified names?
Boolean
SupportsMetadata
Does the workspace support metadata?
Boolean
CanAnalyze
Can the workspace analyze tables?
Boolean
CanGetConfigurationKeywords
Can the workspace retrieve configuration keywords?
Boolean
IsGeoDatabase
Is the workspace a geodatabase?
Boolean
HasPrivateEditSession
Are the workspace's edit sessions privately managed?
Boolean
SupportsHighPrecisionStorage
Is high-precision geometry storage supported?
Boolean
SupportsExtensionDatasets
Does the workspace support the dataset extensibility model?
Boolean
SupportsArchiving
Is archiving supported?
Boolean
SupportsMoveEditsToBase
Is versioning with the option to move edits to base supported?
Boolean
Additionally, there are three workspace properties that are not currently supported by (or fully implemented by) any workspaces, but might be in the future (MaxWhereClauseLength, LastCompressDate, and LastCompressStatus).
The following table shows a complete list of workspace table properties:
Property name
Description
Return type
RowCountIsCalculated
Are row counts calculated upon request?
Boolean
CanAddField
Can fields be added to tables?
Boolean
CanDeleteField
Can fields be deleted from tables?
Boolean
CanAddIndex
Can indexes be added to tables?
Boolean
CanDeleteIndex
Can indexes be deleted from tables?
Boolean
OIDIsRecordNumber
Are record numbers used as Object IDs?
Boolean
MaxFieldNameLength
What is the maximum number of characters that a field name can have?
Int32
BindCursor
Is cursor binding supported?
Boolean
SupportsMultiColumnIndexes
Are multi-column indexes supported?
Boolean
Workspace properties can be accessed from a workspace, through the IWorkspaceProperties interface. See the following illustration:
The second parameter of IWorkspaceProperties.Property is not strongly typed to a single enumeration, because the enumeration type that should be used depends on the value of the first parameter. To query a workspace property, the first parameter should be a value of esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup (an esriWorkspacePropertyGroupType constant) and the second parameter should be a value from the esriWorkspacePropertyType enumeration. To query a workspace table property, the first parameter should be a value of esriWorkspacePropertyGroupType.esriWorkspaceTablePropertyGroup (an esriWorkspacePropertyGroupType constant) and the second should be a value from the esriWorkspaceTablePropertyType enumeration. Depending on the language and compiler parameters used, the second value might or might not have to be explicitly cast to a 32-bit integer.
Since every workspace is not "aware" of every property, IWorkspaceProperty.IsSupported indicates whether a workspace can be queried for a specific property. IsSupported should be checked before accessing the PropertyValue property. The following code example shows how to display a workspace property to the console:
[C#]
public int GetMaximumFieldNameLength(IWorkspace workspace)
{
    // Get the workspace property.
    IWorkspaceProperties workspaceProperties=workspace as IWorkspaceProperties;
    if (workspaceProperties == null)
    {
        throw new ArgumentException(
            "Workspace does not implement IWorkspaceProperties.");
    }
    IWorkspaceProperty workspaceProperty=workspaceProperties.get_Property
        (esriWorkspacePropertyGroupType.esriWorkspaceTablePropertyGroup, (int)
        esriWorkspaceTablePropertyType.esriTablePropMaxFieldNameLength);

    // See if the property is supported.
    if (workspaceProperty.IsSupported)
    {
        // Get the property value.
        object propertyValue=workspaceProperty.PropertyValue;
        return Convert.ToInt32(propertyValue);
    }
    else
    {
        throw new Exception("The esriTablePropMaxFieldNameLength property is " + 
            "not supported by this workspace.");
    }
}
[VB.NET]
Public Function GetMaximumFieldNameLength(ByVal workspace As IWorkspace) As Integer
    ' Get the workspace property.
    Dim workspaceProperties As IWorkspaceProperties=TryCast(workspace, IWorkspaceProperties)
    If workspaceProperties Is Nothing Then
        Throw New ArgumentException("Workspace does not implement IWorkspaceProperties.")
    End If
    Dim workspaceProperty As IWorkspaceProperty=workspaceProperties.Property _
                                                  (esriWorkspacePropertyGroupType.esriWorkspaceTablePropertyGroup, _
                                                  CInt(esriWorkspaceTablePropertyType.esriTablePropMaxFieldNameLength))
    
    ' See if the property is supported.
    If workspaceProperty.IsSupported Then
        ' Get the property value.
        Dim propertyValue As Object=workspaceProperty.PropertyValue
        Return CInt(propertyValue)
    Else
        Throw New Exception("The esriTablePropMaxFieldNameLength property is " + _
                            "not supported by this workspace.")
    End If
End Function
To effectively evaluate a property value (that is, to include the result in logic), the return type must be known. Because workspace properties can return different types of values, it is a developer's responsibility to know the type of value that will be returned from a property, and to cast it appropriately.

Geodatabase release information

The version of a geodatabase can be queried using the IGeodatabaseRelease interface. It can be used to determine whether the geodatabase release number is current with the client, whether a specific dataset type is supported by the geodatabase, and (if the geodatabase is an older release) whether the client can upgrade the geodatabase. Additionally, the IGeodatabaseRelease2 interface can be used to determine whether or not the geodatabase supports a specific type of dataset.
The following code example shows how the IGeodatabaseRelease interface can be used to upgrade an older geodatabase to the current release:
[C#]
public void UpgradeGeodatabase(IWorkspace workspace)
{
    // Display the current version of the geodatabase.
    IGeodatabaseRelease2 gdbRelease=(IGeodatabaseRelease2)workspace;
    Console.WriteLine("GDB release: {0}.{1}.{2}", gdbRelease.MajorVersion,
        gdbRelease.MinorVersion, gdbRelease.BugfixVersion);
    if (gdbRelease.CurrentRelease)
    {
        Console.WriteLine("This geodatabase is current with the client.");
    }
    else
    {
        Console.WriteLine("This geodatabase is not current with the client.");

        // Try to upgrade the geodatabase.
        if (gdbRelease.CanUpgrade)
        {
            try
            {
                Console.WriteLine("Upgrading the geodatabase...");
                gdbRelease.Upgrade();
                Console.WriteLine("The new GDB release: {0}.{1}.{2}",
                    gdbRelease.MajorVersion, gdbRelease.MinorVersion,
                    gdbRelease.BugfixVersion);
            }
            catch (COMException comExc)
            {
                Console.WriteLine("Upgrading the geodatabase failed:");
                Console.WriteLine("{0} ({1})", comExc.Message, comExc.ErrorCode);
            }
        }
        else
        {
            Console.WriteLine("The geodatabase could not be upgraded.");
        }
    }
}
[VB.NET]
Public Sub UpgradeGeodatabase(ByVal workspace As IWorkspace)
    ' Display the current version of the geodatabase.
    Dim gdbRelease As IGeodatabaseRelease2=CType(workspace, IGeodatabaseRelease2)
    Console.WriteLine("GDB release: {0}.{1}.{2}", gdbRelease.MajorVersion, _
                      gdbRelease.MinorVersion, gdbRelease.BugfixVersion)
    If gdbRelease.CurrentRelease Then
        Console.WriteLine("This geodatabase is current with the client.")
    Else
        Console.WriteLine("This geodatabase is not current with the client.")
        
        ' Try to upgrade the geodatabase.
        If gdbRelease.CanUpgrade Then
            Try
            Console.WriteLine("Upgrading the geodatabase...")
            gdbRelease.Upgrade()
            Console.WriteLine("The new GDB release: {0}.{1}.{2}", _
                              gdbRelease.MajorVersion, gdbRelease.MinorVersion, _
                              gdbRelease.BugfixVersion)
            Catch comExc As COMException
            Console.WriteLine("Upgrading the geodatabase failed:")
            Console.WriteLine("{0} ({1})", comExc.Message, comExc.ErrorCode)
            End Try
        Else
            Console.WriteLine("The geodatabase could not be upgraded.")
        End If
    End If
End Sub

Configuration keywords

Configuration keywords represent a setting or a group of settings that tell the geodatabase where or in what format to store data contents in each dataset within ArcSDE and file geodatabases. For more information on configuration keywords and parameters, see the ArcGIS Desktop Help topic, What are configuration keywords?.
To access a list of available configuration keywords programmatically, developers can use the IWorkspaceConfiguration interface, which defines a single property, ConfigurationKeywords. This returns an enumerator of configuration keywords. Each configuration keyword has properties that describe it and a list of parameters that can be accessed through an enumerator.
ArcSDE configuration keywords cannot be created or modified using the ArcObjects application programming interface (API). For information on how to customize configuration keywords, see the ArcGIS Desktop Help topic, Default configuration keywords specific to DB2. File geodatabase configuration keywords cannot be created or modified.
The following code example shows how to access configuration keywords in a geodatabase and display their properties and parameters:
[C#]
public void DisplayConfigurationKeywords(IWorkspace workspace)
{
    // Get a configuration keyword enumerator.
    IWorkspaceConfiguration workspaceConfig=(IWorkspaceConfiguration)workspace;
    IEnumConfigurationKeyword enumConfigKeyword =
        workspaceConfig.ConfigurationKeywords;
    enumConfigKeyword.Reset();

    // Iterate through the configuration keywords.
    IConfigurationKeyword configKeyword=null;
    while ((configKeyword=enumConfigKeyword.Next()) != null)
    {
        // Display the keyword properties.
        Console.WriteLine("Name: {0}", configKeyword.Name);
        Console.WriteLine("Type: {0}", configKeyword.KeywordType);
        Console.WriteLine("Description: {0}", configKeyword.Description);
        Console.WriteLine("Comments: {0}", configKeyword.Comments);

        // Iterate through the keyword parameters.
        IEnumConfigurationParameter enumConfigParameter =
            configKeyword.ConfigurationParameters;
        enumConfigParameter.Reset();
        IConfigurationParameter configParameter=null;
        while ((configParameter=enumConfigParameter.Next()) != null)
        {
            Console.WriteLine("Parameter: {0} ({1})", configParameter.Name,
                configParameter.ConfigurationString);
        }
    }
}
[VB.NET]
Public Sub DisplayConfigurationKeywords(ByVal workspace As IWorkspace)
    ' Get a configuration keyword enumerator.
    Dim workspaceConfig As IWorkspaceConfiguration=CType(workspace, IWorkspaceConfiguration)
    Dim enumConfigKeyword As IEnumConfigurationKeyword=workspaceConfig.ConfigurationKeywords
    enumConfigKeyword.Reset()
    
    ' Iterate through the configuration keywords.
    Dim configKeyword As IConfigurationKeyword=enumConfigKeyword.Next()
    While Not configKeyword Is Nothing
        ' Display the keyword properties.
        Console.WriteLine("Name: {0}", configKeyword.Name)
        Console.WriteLine("Type: {0}", configKeyword.KeywordType)
        Console.WriteLine("Description: {0}", configKeyword.Description)
        Console.WriteLine("Comments: {0}", configKeyword.Comments)
        
        ' Iterate through the keyword parameters.
        Dim enumConfigParameter As IEnumConfigurationParameter=configKeyword.ConfigurationParameters
        enumConfigParameter.Reset()
        Dim configParameter As IConfigurationParameter=enumConfigParameter.Next()
        While Not configParameter Is Nothing
            Console.WriteLine("Parameter: {0} ({1})", configParameter.Name, configParameter.ConfigurationString)
            configParameter=enumConfigParameter.Next()
        End While
        
        configKeyword=enumConfigKeyword.Next()
    End While
End Sub

Database connection information

The IDatabaseConnectionInfo and IDatabaseConnectionInfo2 interfaces are implemented by ArcSDE geodatabases to provide information about a workspace's connection. The following code example shows how to use the interfaces to get the name of the workspace's server, name of the connected user, name of the database, type of database (that is, Oracle, Structured Query Language [SQL] Server), and the server class (that is, personal, workgroup, or enterprise):
[C#]
public void DisplayConnectionInfo(IWorkspace workspace)
{
    IDatabaseConnectionInfo2 connectionInfo=(IDatabaseConnectionInfo2)workspace;
    Console.WriteLine("Server: {0}", connectionInfo.ConnectionDBMS);
    Console.WriteLine("User: {0}", connectionInfo.ConnectedUser);
    Console.WriteLine("Database: {0}", connectionInfo.ConnectedDatabase);
    Console.WriteLine("DBMS: {0}", connectionInfo.ConnectionDBMS);
    Console.WriteLine("Server Class: {0}", connectionInfo.GeodatabaseServerClass);
}
[VB.NET]
Public Sub DisplayConnectionInfo(ByVal workspace As IWorkspace)
    Dim connectionInfo As IDatabaseConnectionInfo2=CType(workspace, IDatabaseConnectionInfo2)
    Console.WriteLine("Server: {0}", connectionInfo.ConnectionDBMS)
    Console.WriteLine("User: {0}", connectionInfo.ConnectedUser)
    Console.WriteLine("Database: {0}", connectionInfo.ConnectedDatabase)
    Console.WriteLine("DBMS: {0}", connectionInfo.ConnectionDBMS)
    Console.WriteLine("Server Class: {0}", connectionInfo.GeodatabaseServerClass)
End Sub

Determining if a workspace is an enterprise geodatabase

The following code example can be used to determine if a workspace that has been connected to is a enterprise geodatabase:
[C#]
public bool IsConnectedToGeodatabase(IWorkspace workspace)
{
    // The following code will use the workspace properties to determine if the workspace is an enterprise geodatabase or a database.
    IWorkspaceProperties workspaceProperties=(IWorkspaceProperties)workspace;
    IWorkspaceProperty isGDBProperty=workspaceProperties.get_Property
        (esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup, (int)
        esriWorkspacePropertyType.esriWorkspacePropIsGeoDatabase);
    object isGDB=isGDBProperty.PropertyValue;
    Boolean isGeodatabase=Convert.ToBoolean(isGDB);
    return isGeodatabase;
}
[VB.NET]
Public Function IsConnectedToGeodatabase(ByVal workspace As ESRI.ArcGIS.Geodatabase.IWorkspace) As Boolean
    'The following code will use the workspace properties to determine if the workspace is an enterprise geodatabase or a database.
    Dim workspaceProperties As ESRI.ArcGIS.Geodatabase.IWorkspaceProperties=CType(workspace, ESRI.ArcGIS.Geodatabase.IWorkspaceProperties) 'Explicit Cast
    Dim isGDBProperty As ESRI.ArcGIS.Geodatabase.IWorkspaceProperty
    isGDBProperty=workspaceProperties.Property(ESRI.ArcGIS.Geodatabase.esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup, _
                    ESRI.ArcGIS.Geodatabase.esriWorkspacePropertyType.esriWorkspacePropIsGeoDatabase)
    IsConnectedToGeodatabase=isGDBProperty.PropertyValue
End Function






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):

Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine