I want to update a feature layer's data source from one OLE DB connection to another OLE DB connection in the project using arcpy. This OLE DB connection connects to a .mdb The code runs no problem, but the data source did not change. What is wrong with my code? Thank you so much!!
import arcpy
import os
aprx = arcpy.mp.ArcGISProject("CURRENT")
project_path = aprx.filePath # Get the file path of the current project
directory, filename = os.path.split(project_path)
odc_filename = "Data.odc"
ole_db_connection = os.path.join(directory, odc_filename)
print(ole_db_connection)
# Set the workspace to the OLE DB connection
# arcpy.env.workspace = ole_db_connection
#Get the map from the project (assuming the first map in the project)
map = aprx.listMaps()[0]
layer = map.listLayers("Layer_1")[0]
# Define the current and new connection properties
old_connection = layer.connectionProperties
#new_connection = odc_project_path
new_connection = old_connection.copy()
# Update the workspace path and dataset name
new_connection['event_table_source']['connection_info']['connectstring'] = ole_db_connection
layer.updateConnectionProperties(old_connection, new_connection)
You might need to save the apex at the end of the code?
Unfortunately I tried and it didn't work. I think it is the OLE link, I might need to define something else, but I don't know how.