<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using updateConnectionProperties to update a single layer with ArcPy in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1371865#M77608</link>
    <description>&lt;P&gt;An issue for some as noted.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;says&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If no matches are found when you replace the current_connection_info parameter with the new_connection_info parameter in the updateConnectionProperties function, your script may complete, but nothing will be updated.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The code examples seem to prefer/expect that saveACopy. unless you break the connections first (topic 5)&lt;/P&gt;&lt;P&gt;The other related threads don't provide and simple direct solutions either.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2024 19:54:06 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2024-01-18T19:54:06Z</dc:date>
    <item>
      <title>Using updateConnectionProperties to update a single layer with ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1371637#M77587</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to automate a process for my collegues with ArcPy. A part of this process is to change the datasource of a single layer in a map to a new File Geodatabase. After searching the documentation i found this would be possible by using the updateConnectionProperties. I've been trying to get the following script to work, but no success so far:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

# parameters
path = r"C:\MyProjects\ProjectX"
project = r"Kadastraal.aprx"
aprx = arcpy.mp.ArcGISProject(path+"\\"+project)
mapx = aprx.listMaps("Vastgoedobject1")[0]
layer = mapx.listLayers("Vastgoedobject")

#Change datasource of specified layer
old_file = r"C:\Data\OldData.gdb"
new_file = r"C:\NewData\newData.gdb"
for lyr in layer:
    print (lyr.connectionProperties)
    print ("Start updating datasource: " + lyr.name)
    lyr.updateConnectionProperties({'dataset': 'Percelen_poly', 
    'workspace_factory': 'File Geodatabase', 'connection_info': {'database': 
    old_file}}, {'dataset': 'Percelen_poly', 'workspace_factory': 'File 
    Geodatabase', 'connection_info': {'database': nieuw_bestand}})
    print("Datasource of " + lyr.name + " is updated")
    print (lyr.connectionProperties)&lt;/LI-CODE&gt;&lt;P&gt;This gives no errors for me and if i look at the print statements it seems to update the source. But if i look at the map it still shows the old connection.&lt;/P&gt;&lt;P&gt;The only way i have found it works is if i add aprx.&lt;SPAN&gt;saveACopy&amp;nbsp;(r"C:\Temp"). Then the connection is updated in the new aprx file. I tried using aprx.save() instead. but that just gives met the below error. Is this a known issue? Or am i doing something wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;OSError                                   Traceback (most recent call last)
In  [19]:
Line 22:    aprx.save()

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py, in save:
Line 333:   return convertArcObjectToPythonObject(self._arc_object.save(*gp_fixargs((), True)))

OSError: C:\MyProjects\ProjectX\Kadastraal.aprx&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Jan 2024 15:26:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1371637#M77587</guid>
      <dc:creator>Jeroen_S</dc:creator>
      <dc:date>2024-01-18T15:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using updateConnectionProperties to update a single layer with ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1371865#M77608</link>
      <description>&lt;P&gt;An issue for some as noted.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;says&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If no matches are found when you replace the current_connection_info parameter with the new_connection_info parameter in the updateConnectionProperties function, your script may complete, but nothing will be updated.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The code examples seem to prefer/expect that saveACopy. unless you break the connections first (topic 5)&lt;/P&gt;&lt;P&gt;The other related threads don't provide and simple direct solutions either.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 19:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1371865#M77608</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-01-18T19:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using updateConnectionProperties to update a single layer with ArcPy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1501337#M85230</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/755439"&gt;@Jeroen_S&lt;/a&gt;&amp;nbsp; I solved it.&amp;nbsp; I deserve a medal and a cumulative ~16 hours of my life back from multiple thwarted attempts to figure this issue out over the past two years.&amp;nbsp; On that note, I hope &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;already has one, because he's the constant anchor of reason, answering questions on these forums.&amp;nbsp; Anyways, it must be a bug.&amp;nbsp; But your clue to&amp;nbsp;&lt;STRONG&gt;aprx.saveACopy()&amp;nbsp;&lt;/STRONG&gt;to a different location&amp;nbsp;worked(!) and subsequently got me tinkering.&amp;nbsp; The solution to this bug is to load the aprx object as such:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('current')
# Then do all the exact same dataConnection updates and save with the path
aprx.saveACopy(fp_aprx)&lt;/LI-CODE&gt;&lt;P&gt;So, basically just load the aprx object using&amp;nbsp;&lt;STRONG&gt;"current"&lt;/STRONG&gt; not&amp;nbsp;&lt;STRONG&gt;"path/to/project.aprx"&lt;/STRONG&gt;.&amp;nbsp; I think this is specific to various changes we are making to the dataConnection, because I've passed &lt;STRONG&gt;path/to/aprx&amp;nbsp;&lt;/STRONG&gt;under different circumstances, i.e. same gdb, but remapping to updated names (i.e. &amp;lt;filename&amp;gt;_v2).&amp;nbsp; Anyways, below is a post I made today prior to determining the issue.&amp;nbsp; Nice work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;A title="Update Data Connection CIM" href="https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-cim/m-p/1501311#M85225" target="_self"&gt;Update Data Connection CIM&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 21:27:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1501337#M85230</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2024-07-03T21:27:16Z</dc:date>
    </item>
  </channel>
</rss>

