ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Datastore Class / GetConnector Method
Example

In This Topic
    GetConnector Method (Datastore)
    In This Topic
    Gets the Connector associated with the currently opened data store. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public MustOverride Function GetConnector() As Connector
    public abstract Connector GetConnector()

    Return Value

    The Connector associated with the currently opened data store.
    Exceptions
    ExceptionDescription
    No valid data store has been opened prior to invoking this operation.
    A geodatabase-related exception has occurred.
    Example
    Get the Data Connection Properties from a Feature Service
    {
      await QueuedTask.Run(() =>
      {
        Layer selectedLayer = MapView.Active.GetSelectedLayers()[0];
    
        if (selectedLayer is FeatureLayer)
        {
          FeatureLayer featureLayer = selectedLayer as FeatureLayer;
    
          using (Table table = featureLayer.GetTable())
          using (Datastore datastore = table.GetDatastore())
          {
            ServiceConnectionProperties serviceConnectionProperties = datastore.GetConnector() as ServiceConnectionProperties;
    
            if (serviceConnectionProperties == null)
              return;
    
            Uri url = serviceConnectionProperties.URL;      // Will be the URL to the Feature Service.
            string user = serviceConnectionProperties.User;     // The username property will only be
                                                                // populated for feature service hosted
                                                                // on non-federated ArcGIS Server.
            string password = serviceConnectionProperties.Password; // Will always be empty.
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also