How to access data source of feature layer? IDataLayer2.DataSourceName.NameString does not work.

1161
2
Jump to solution
09-29-2016 04:28 PM
SeanNakasone
New Contributor II

Hi, how do I obtain the data source of a feature layer in a map document, see pic below.

I tried to use...

IDataLayer2.DataSourceName.NameString

But it seems like DataSourceName is a COM object.

DataSourceName is described here...

http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//001200000380000000

It seems like it should just work.

Suggestions?

0 Kudos
1 Solution

Accepted Solutions
KarlHuber
New Contributor III

The datasource for a feature layer can be queried directly from the FeatureClass property:

IFeatureLayer featureLayer = ...

IFeatureClass featureClass = featureLayer.FeatureClass;

IWorkspace workspace = ((IDataset)featureClass).Workspace;

there's IMHO no need to evalute the IDataLayer2.DataSourceName property explicitly unless you need some more information about the datasource:

var dataSourceName = dataLayer.DataSourceName as IDatasetName;

ISQLSyntax sqlSyntax = (ISQLSyntax)workspace;

string tableName;

string dbName;

string ownerName;

sqlSyntax.ParseTableName(dataSourceName .Name, out dbName, out ownerName, out tableName);

View solution in original post

0 Kudos
2 Replies
KarlHuber
New Contributor III

The datasource for a feature layer can be queried directly from the FeatureClass property:

IFeatureLayer featureLayer = ...

IFeatureClass featureClass = featureLayer.FeatureClass;

IWorkspace workspace = ((IDataset)featureClass).Workspace;

there's IMHO no need to evalute the IDataLayer2.DataSourceName property explicitly unless you need some more information about the datasource:

var dataSourceName = dataLayer.DataSourceName as IDatasetName;

ISQLSyntax sqlSyntax = (ISQLSyntax)workspace;

string tableName;

string dbName;

string ownerName;

sqlSyntax.ParseTableName(dataSourceName .Name, out dbName, out ownerName, out tableName);

0 Kudos
SeanNakasone
New Contributor II

Thank you very much

0 Kudos