<?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: Change db connection properties of layer files in a folder (SDE to SDE) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114767#M62922</link>
    <description>&lt;P&gt;Thanks for taking the time to reply Dan.&lt;/P&gt;&lt;P&gt;I actually experimented with the suggestions on the link you provided. However I am hoping to stick with .lyr files. The apps&amp;nbsp; dependant on the layer files may not be able to handle .lyrx files.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Nov 2021 20:28:52 GMT</pubDate>
    <dc:creator>JavadSalimi</dc:creator>
    <dc:date>2021-11-07T20:28:52Z</dc:date>
    <item>
      <title>Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114760#M62920</link>
      <description>&lt;P&gt;I would really appreciate some of you ESRI and Python experts to lend a hand to me on this subject. I have a number of folders that each contain countless layer files (.lyr). All of the layer files reference an old SDE db connection and the task at hand is to change them all to a new SDE connection using Python.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There seems to be a lot of forum submissions describing a similar requirement but not ending well due to some limitations with objects or python, or some combination thereof. I am hoping to get any insight at this point. A lot of examples involve changing the data connection prooperties of layers in a map (.mxd), but in my case, they are not managed this way...they're in file folders.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something along the lines of:&lt;/P&gt;&lt;P&gt;for every layer file in a folder change the db connection from SDE1 to SDE2&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 19:43:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114760#M62920</guid>
      <dc:creator>JavadSalimi</dc:creator>
      <dc:date>2021-11-07T19:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114765#M62921</link>
      <description>&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;&amp;nbsp;would this be what you are referring to?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114765#M62921</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-11-07T20:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114767#M62922</link>
      <description>&lt;P&gt;Thanks for taking the time to reply Dan.&lt;/P&gt;&lt;P&gt;I actually experimented with the suggestions on the link you provided. However I am hoping to stick with .lyr files. The apps&amp;nbsp; dependant on the layer files may not be able to handle .lyrx files.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 20:28:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114767#M62922</guid>
      <dc:creator>JavadSalimi</dc:creator>
      <dc:date>2021-11-07T20:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114769#M62923</link>
      <description>&lt;P&gt;You can try something like within your for loop&lt;/P&gt;&lt;PRE&gt;lyr.findAndReplaceWorkspacePath(find_workspace_path=lyr.dataSource, replace_workspace_path=r"C:\Newpath\To\SDE_ConnectionFile.sde")&lt;/PRE&gt;&lt;P&gt;Lots of examples here:&amp;nbsp;&lt;A href="https://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000.htm" target="_blank" rel="noopener"&gt;Desktop Help 10.0 - Updating and fixing data sources with arcpy.mapping (arcgis.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 21:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114769#M62923</guid>
      <dc:creator>tigerwoulds</dc:creator>
      <dc:date>2021-11-07T21:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114774#M62924</link>
      <description>&lt;P&gt;Thank you for the response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is some promise here. I have the following so far but after the "for", only the print line works, the others return the error "AttributeError: 'unicode' object has no attribute 'findAndReplaceWorkspacePath'".&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = r"\\...\layerfiletest"&lt;BR /&gt;lyrFileList = arcpy.ListFiles("*.lyr")&lt;BR /&gt;for lyr in lyrFileList:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #print lyrFile&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #lyr.findAndReplaceWorkspacePaths(r"\\...User.sde", r"\\...User.sde")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #lyr.findAndReplaceWorkspacePath(find_workspace_path=lyr.dataSource, replace_workspace_path=r"\\...User.sde")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #lyr.findAndReplaceWorkspacePath(lyr.dataSource, r"\\...User.sde")&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 23:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114774#M62924</guid>
      <dc:creator>JavadSalimi</dc:creator>
      <dc:date>2021-11-07T23:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114775#M62925</link>
      <description>&lt;P&gt;python isn't going to understand your path&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;r"\\...User.sde"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;the error is in the path name, so you will have to provide it or check for spaces, international characters, punctuation and the like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 23:15:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114775#M62925</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-11-07T23:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114776#M62926</link>
      <description>&lt;P&gt;Sorry to confuse the matter. I have a proper path but just tried hiding it. Please assume they are correct.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Nov 2021 23:25:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114776#M62926</guid>
      <dc:creator>JavadSalimi</dc:creator>
      <dc:date>2021-11-07T23:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114778#M62927</link>
      <description>&lt;P&gt;If you can post the full code you are using (change folder and drive letter names if you want) that is a better option. You can also try&amp;nbsp;&lt;SPAN&gt;lyr.replaceDataSource&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 00:18:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114778#M62927</guid>
      <dc:creator>tigerwoulds</dc:creator>
      <dc:date>2021-11-08T00:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change db connection properties of layer files in a folder (SDE to SDE)</title>
      <link>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114779#M62928</link>
      <description>&lt;P&gt;I don't have much more but, for clarity I have posted with the full paths:&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;folderpathLayerFiles = r"\\corp\roaming\redirected\jds\Desktop\test\layerfiletest2"&lt;BR /&gt;lyrFileList = arcpy.ListFiles("*.lyr")&lt;BR /&gt;for lyr in lyrFileList:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#print lyrFile&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#lyr = arcpy.mapping.Layer(os.path.join(folderpathLayerFiles,lyrFile))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#print lyr.dataSource&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;#lyr.findAndReplaceWorkspacePath(find_workspace_path=lyr.dataSource,&amp;nbsp; &amp;nbsp; replace_workspace_path=r"\\server\gis_work\GIS_Layers\Connection File\User@SDE.sde")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #lyr.findAndReplaceWorkspacePath(lyr.dataSource, r"\\server\gis_w\GIS_Layers\Connection File\User@SDE.sde")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; #lyr.findAndReplaceWorkspacePath(r"\\server\gis_w\GIS_Layers\User@SDE.sde", r"\\server\gis_work\GIS_Layers\Connection File\User@SDE.sde")&lt;/P&gt;&lt;P&gt;I tried lyr.replaceDataSource as well but go the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 00:29:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-db-connection-properties-of-layer-files-in/m-p/1114779#M62928</guid>
      <dc:creator>JavadSalimi</dc:creator>
      <dc:date>2021-11-08T00:29:02Z</dc:date>
    </item>
  </channel>
</rss>

