ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Core.Data Namespace / ServiceConnectionProperties Class / Password Property
Example

In This Topic
    Password Property (ServiceConnectionProperties)
    In This Topic
    The password used to connect to the service.
    Syntax
    public string Password {get; set;}
    Public Property Password As String
    Example
    Get the Data Connection Properties from a Feature Service
    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.
        }
    }
    
    Connect to an AGS Service using ServiceConnectionProperties
          //Connect to the AGS service. Note: the connection will persist for the
          //duration of the Pro session.
          var serverUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services";
    
          var username = "user1";
          var password = "user1";
    
    await QueuedTask.Run(() =>
    {
      //at any point before creating a layer, first make a connection to the server
      //if one has not been already established for the current session
      var uri = new Uri(serverUrl);
      var props = new ServiceConnectionProperties(uri)
      {
        User = username
      };
      //It is preferred that you use the Windows Credential Manager to store the password
    
      //However, it can be set as clear text if you so choose
      props.Password = password; //not recommended
    
              //Establish a connection to the server at any point in time _before_
              //creating a layer from a service on the server
              var gdb = new Geodatabase(props);
      gdb.Dispose();//you do not need the geodatabase object after you have connected.
    });
    
          //later in the session, as needed...create a layer from one of the services
    //on the server
          var serviceUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/MapServer";
    var map = MapView.Active.Map;
    
          QueuedTask.Run(() =>
          {
              var lc = new LayerCreationParams(new Uri(serviceUrl));
              LayerFactory.Instance.CreateLayer<MapImageLayer>(lc, map);
          });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also