<?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: Changing SDE Data Sources in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230353#M17856</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After alot of frustration, I finally got this to work thanks to this thread:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/40806-Replace-Data-Sources-from-shapefile-to-feature-dataset-feature-class-in-an-mxd-using?highlight=replace+source"&gt;http://forums.arcgis.com/threads/40806-Replace-Data-Sources-from-shapefile-to-feature-dataset-feature-class-in-an-mxd-using?highlight=replace+source&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps someone else out there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Jul 2012 19:09:05 GMT</pubDate>
    <dc:creator>JohnMax</dc:creator>
    <dc:date>2012-07-27T19:09:05Z</dc:date>
    <item>
      <title>Changing SDE Data Sources</title>
      <link>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230351#M17854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have hundreds of mxd's with broken links due to migration to a different SDE server.&amp;nbsp; I know how to change to the new SDE connection using the &lt;/SPAN&gt;&lt;STRONG&gt;findAndReplaceWorkspacePaths&lt;/STRONG&gt;&lt;SPAN&gt; method.&amp;nbsp; My problem is that the Feature Dataset that the Feature Classes were previously under is renamed in the new SDE database.&amp;nbsp; This causes all of the links to still be broken. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to fix this programmatically using Python?&amp;nbsp; I am a newbie, so any code examples would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 14:38:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230351#M17854</guid>
      <dc:creator>JohnMax</dc:creator>
      <dc:date>2012-05-16T14:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Changing SDE Data Sources</title>
      <link>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230352#M17855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Seems like you have two major tasks. 1, to access all your MXDs and 2, to switch the SDE connection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) I've used "os.listdir" to list out all folders/files in a directory. This assumes you are using systematic folder system. Here's a sample:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, arcpy

masterPath = "C:\\MXDs"
sites = os.listdir(sitesPath)

for site in sites:
 if ".mxd" in site or ".MXD" in site: #checks if file is a map document
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(masterPath+"\\"+site)
&amp;nbsp; #==========
&amp;nbsp; #do stuff to MXDs here:

&amp;nbsp; #==========
&amp;nbsp; mxd.save()
&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) You can either go layer by layer in the MXD or sweep for the entire MXD.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The layer by layer would look something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for lyr in arcpy.mapping.ListLayers(mxd):
 if lyr.isFeatureLayer and ".sde" in lyr.dataSource: #'isGroupLayer' must be tested before 'dataSource'
&amp;nbsp; lyr.replaceDataSource(newPathSDE, "SDE_WORKSPACE", lyr.datasetName)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;The entire MXD sweep would look something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd.replaceWorkspaces("C:\\connections\\OldSDEconnection.sde", "SDE_WORKSPACE", "C:\\connections\\NewSDEconnection.sde", "SDE_WORKSPACE")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;~Josh&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:12:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230352#M17855</guid>
      <dc:creator>JoshuaChisholm</dc:creator>
      <dc:date>2021-12-11T11:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Changing SDE Data Sources</title>
      <link>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230353#M17856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After alot of frustration, I finally got this to work thanks to this thread:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/40806-Replace-Data-Sources-from-shapefile-to-feature-dataset-feature-class-in-an-mxd-using?highlight=replace+source"&gt;http://forums.arcgis.com/threads/40806-Replace-Data-Sources-from-shapefile-to-feature-dataset-feature-class-in-an-mxd-using?highlight=replace+source&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps someone else out there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jul 2012 19:09:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230353#M17856</guid>
      <dc:creator>JohnMax</dc:creator>
      <dc:date>2012-07-27T19:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Changing SDE Data Sources</title>
      <link>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230354#M17857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I used the same source but got a big exception during line replaceDataSource&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2019 10:46:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-sde-data-sources/m-p/230354#M17857</guid>
      <dc:creator>JosephJose</dc:creator>
      <dc:date>2019-04-11T10:46:06Z</dc:date>
    </item>
  </channel>
</rss>

