HOW TO

Change the data source properties of a layer from a file geodatabase feature class to a feature service feature class using ArcPy in ArcGIS Pro

Last Published: August 14, 2025

Summary

After publishing a feature layer to ArcGIS Online, a user may want to change the data source of the layer in a file geodatabase in ArcGIS Pro to the layer they just published. This requires changing the data source properties. This can be done through the UI by right-clicking the desired layer > Properties > Source > Set Data source, and selecting the feature layer that was just published in ArcGIS Online

This process can also be automated through Python using ArcPy in ArcGIS Pro:

According to this documentation: How to: Change the data source of a layer from referencing a geodatabase to an ArcGIS Server URL in ArcGIS Pro using ArcPy, The l.updateConnectionProperties is the function to use. The issue is that this function only changes the data source on the backend, and it does not reflect in the data source path in the properties of the layer. Even though this does technically work, there is a better script to use to have the new change reflected in both the backend and in the UI Layer Properties (Source tab).

Procedure

The data source must be updated using the CIM (Cartographic Information Model). This is used when a specific data source workflow is difficult to accomplish using the updateConnectionProperties function mentioned above.

This script updates the data source from geodatabase to feature service and the UI will properly update as well:

aprx = arcpy.mp.ArcGISProject('CURRENT')
m = aprx.listMaps('Map')[0]
lyr = m.listLayers()[0]
c = lyr.getDefinition('V3')
dc = c.featureTable.dataConnection
dc.workspaceConnectionString = "URL=Feature Service URL"
dc.workspaceFactory = "FeatureService"
dc.dataset = "0"
lyr.setDefinition(c)

Article ID: 000036475

Software:
  • ArcGIS Online

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options