I am using ArcObjects v10.0 with a SQL Server 2008 database. Given the name of a Layer, is there a way for me to extract the corresponding name of the database table that represents that Layer?

The Layer name and the Database Table name will often be identical, but they will not in cases where the Layer name contains invalid characters, such as spaces.

2 Answers 2


Here you go:

IFeatureLayer fl = ...;
string tablename = ((IDataset)fl.FeatureClass).BrowseName;

Link: IDataset.BrowseName API Docs

  • Thanks, but how would you retrieve the IFeatureLayer, given only it's name? Mar 28, 2011 at 18:40
  • That would depend on what you're trying to get the layer from. Whether its a desktop tool working with an MXD, ArcObjects code working on server, etc. Generally though if you can get an IMap object, you can loop through all the layers by calling map.get_Layers() and use the layer name to find the right ILayer object, then cast that ILayer object to an IFeatureLayer (if it in fact implements IFeatureLayer). Mar 28, 2011 at 18:54
  • It's a desktop tool working with an iWorkspace object based on an SDE service. Mar 28, 2011 at 20:16
    public static string GetServerNameForLayer(ILayer pLayer)
            if (pLayer == null) return "";
            ESRI.ArcGIS.Carto.IDataLayer pDataLayer = pLayer as IDataLayer; // QI 
            if (pDataLayer == null) return "";
            ESRI.ArcGIS.Geodatabase.IDatasetName pDatasetName = pDataLayer.DataSourceName as IDatasetName; ; // QI 
            if (pDatasetName == null) return "";
            ESRI.ArcGIS.Carto.IFeatureLayer pFeatLayer = pLayer as IFeatureLayer; // QI 
            if (pLayer == null) return "";
            ESRI.ArcGIS.Geodatabase.IDataset pDataset = pFeatLayer as IDataset; // QI 
            if (pDataset == null) return "";
            if (pDatasetName.WorkspaceName.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                if (pDataset.Category == "SDE Feature Class")
                    // Get the SERVER, DATABASE, USER, VERSION
                    ESRI.ArcGIS.esriSystem.IPropertySet2 pConnProps = pDataset.Workspace.ConnectionProperties as IPropertySet2;
                    return Convert.ToString(pConnProps.GetProperty("SERVER"));
                return "";
            return "";
        catch (Exception ex)
            string strErrMsg = "ArcMapFeatureUtils::" + System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
            string crlf = "\r";
            strErrMsg = strErrMsg + " Error: " + ex.Message + crlf + ex.ToString() + crlf;
            //System.Windows.Forms.MessageBox.Show(strErrMsg, "Error");
            return "";
  • 1
    This seems unnecessarily complex and doesn't answer the question which is looking for the table name, not the server name.
    – blah238
    Jan 20, 2012 at 23:47

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.