<?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: updateConnectionProperties() is not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334483#M68811</link>
    <description>&lt;P&gt;Thanks for this suggestion but everything is the exact same aside from the un/pw and permissions set on each. Same database version and everything--just one user has admin permissions and the other user was created for viewing only.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2023 12:38:48 GMT</pubDate>
    <dc:creator>NSamu</dc:creator>
    <dc:date>2023-10-03T12:38:48Z</dc:date>
    <item>
      <title>updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333458#M68770</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to update connection properties for all layers in a Pro project map that are connected to our admin database to a read-only version of that database. When I run the following script, it runs but the database connections do not get updated.&lt;BR /&gt;&lt;BR /&gt;import arcpy&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;for m in aprx.listMaps("Mobile_Map"):&lt;BR /&gt;for lyr in m.listLayers():&lt;BR /&gt;if not(lyr.isGroupLayer or lyr.isBasemapLayer):&lt;BR /&gt;try:&lt;BR /&gt;lyr.updateConnectionProperties(current_connection_info="A:\DBConnection\admin.sde", new_connection_info="A:\DBConnection\dr.sde")&lt;BR /&gt;except:&lt;BR /&gt;print("Not an sde database or the database connection does not need to be updated.")&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 16:40:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333458#M68770</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-09-28T16:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333471#M68771</link>
      <description>&lt;P&gt;I think you need to save the project when you're done.&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;</description>
      <pubDate>Thu, 28 Sep 2023 17:25:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333471#M68771</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-09-28T17:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333502#M68772</link>
      <description>&lt;P&gt;Thank you for the suggestion. I just tried it but it still does not work.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 18:12:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333502#M68772</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-09-28T18:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333516#M68773</link>
      <description>&lt;P&gt;I use something similar to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;proj_gdb = #SDE Source
for lyr in m.listLayers():
    lyr_update = lyr.connectionProperties
    lyr_update['connection_info']['database'] = proj_gdb
    lyr_update['dataset'] = #SDE layer name
    lyr.updateConnectionProperties(lyr.connectionProperties, lyr_update)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: In this example, I'd probably get the source feature class name and, assuming that the target has the same name as the source, use that variable to get the correct target feature class name.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 18:50:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333516#M68773</guid>
      <dc:creator>SorenPeterson</dc:creator>
      <dc:date>2023-09-28T18:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333702#M68779</link>
      <description>&lt;P&gt;Thank you for this--it makes sense to me. I just tried something similar (see code in .txt doc) and it runs but still doesn't work properly. I had to modify the code some since I'm moving the connection from between different users of the same SDE database--the only difference that I can see when printing the database properties of the dr vs. admin database is the user and password. So, I tried to just update those in the code this time...&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 12:22:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1333702#M68779</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-09-29T12:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334111#M68801</link>
      <description>&lt;P&gt;I could see some issues with that code if you change the user/password and the user doesn't have access to the relevant layer. Also if the table has a different name than the current layer, since it'll be looking for the same table name, but with a different connection. I'd recommend taking a look at the source tab in the properties for both the original and the new tables and see if there's any differences that will need to be updated to match beyond the database login. For example if the&amp;nbsp; table name is different such as DBO.layername and User.layername_1, different feature dataset name, different instance name, server ip/hostname.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 13:34:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334111#M68801</guid>
      <dc:creator>SorenPeterson</dc:creator>
      <dc:date>2023-10-02T13:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334483#M68811</link>
      <description>&lt;P&gt;Thanks for this suggestion but everything is the exact same aside from the un/pw and permissions set on each. Same database version and everything--just one user has admin permissions and the other user was created for viewing only.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 12:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334483#M68811</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-10-03T12:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334531#M68812</link>
      <description>&lt;P&gt;I would recommend using the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm#M1_GUID-AE1B6592-5077-4B14-AFF1-BE41E81538CC" target="_self"&gt;supports() method on layer&lt;/A&gt; to check if it has the property "connectionProperties"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for lyr in m.listLayers():
    if lyr.supports("connectionProperties"):
        print(lyr.connectionProperties["connection_info"])
        lyr_update = lyr.connectionProperties
        lyr_update['connection_info']['password']='&amp;lt;password&amp;gt;'
        lyr_update['connection_info']['user']='dr'
        lyr.updateConnectionProperties(lyr.connectionProperties, lyr_update)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 14:19:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334531#M68812</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-03T14:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334560#M68813</link>
      <description>&lt;P&gt;Thanks, Blake. I tried your method using the code below--it ran but did not change the database connection. Please let me know if you have another suggestion or see any issues with my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
for m in aprx.listMaps("Mobile_Map"):
    for lyr in m.listLayers():
        if lyr.supports("connectionProperties"):
            try:
                print(lyr.connectionProperties["connection_info"])
                lyr_update = lyr.connectionProperties
                lyr_update['connection_info']['password']='&amp;lt;password&amp;gt;'
                lyr_update['connection_info']['user']='dr'
                lyr.updateConnectionProperties(lyr.connectionProperties, lyr_update)
                         
            except:     
                print("Not an sde database or the database connection does not need to be updated.")
aprx.save()
del aprx&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 15:36:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334560#M68813</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-10-03T15:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334579#M68814</link>
      <description>&lt;P&gt;Edit: the code above works when I change '&amp;lt;password&amp;gt;' to 'password'. Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;! Much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 15:58:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334579#M68814</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-10-03T15:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334613#M68815</link>
      <description>&lt;P&gt;Oh, glad you got it working!&lt;/P&gt;&lt;P&gt;As another suggestion, consider handling your exceptions a more specific, targeted manner. With your snippet, you will never know if there was some other problem with&amp;nbsp;&lt;SPAN&gt;updateConnectionProperties() because you're printing a generic message for &lt;EM&gt;all&lt;/EM&gt;&amp;nbsp;exceptions. You need to know if something unexpected is happening, which your error handling will not show. I've started doing this as a pattern to add more information/context to errors.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
for m in aprx.listMaps("Mobile_Map"):
    for lyr in m.listLayers():
        if lyr.supports("connectionProperties"):
            try:
                print(lyr.connectionProperties["connection_info"])
                lyr_update = lyr.connectionProperties
                lyr_update['connection_info']['password']='&amp;lt;password&amp;gt;'
                lyr_update['connection_info']['user']='dr'
                lyr.updateConnectionProperties(lyr.connectionProperties, lyr_update)

            except Exception as e:
                raise Exception("Not an sde database or the database connection does not need to be updated.") from e
aprx.save()
del aprx&lt;/LI-CODE&gt;&lt;P&gt;If you really want to pass on some specific error, you can handle that specifically. In this example, all arcpy errors will get passed and the code will continue running, but it will stop if the exception is not from arcpy (unhandled).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;except arcpy.ExecuteError as arcpy_e:
    print(arcpy_e)
    print("Not an sde database or the database connection does not need to be updated.")
    pass&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 Oct 2023 16:45:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334613#M68815</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-10-03T16:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334616#M68816</link>
      <description>&lt;P&gt;Thank you for this advice. Very helpful and much appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 16:51:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1334616#M68816</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-10-03T16:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: updateConnectionProperties() is not working</title>
      <link>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1579323#M73645</link>
      <description>&lt;P&gt;I have to write two Python scripts, one for ArcMap and one for ArcGIS Pro, in order to fix all the geodatabase connections in map documents and Pro projects after we change 30+ passwords at a future date.&amp;nbsp; It's unfortunate that the Pro script will have to access a file (or have hard-coded) all the new passwords in order for this to work!&amp;nbsp; The ArcMap script will have no such problems, with all the testing I've done (the biggest hang-up there is that the "Database" key does not appear in the serviceProperties dictionary when the connection can't be established).&amp;nbsp; No combination of arguments for the updateConnectionProperties method seems to work other than the one marked in this thread as the solution.&amp;nbsp; I would have preferred to just reference a new .sde file, but that just doesn't work.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 23:06:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updateconnectionproperties-is-not-working/m-p/1579323#M73645</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2025-01-27T23:06:36Z</dc:date>
    </item>
  </channel>
</rss>

