<?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 Change MXD data sources to another SDE geodatabase in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470350#M36723</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to change the data source of an MXD to another SDE geodatabase?&amp;nbsp; I've tried this, but have only been able to get this to work when switching versions within the same SDE geodatabase.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd2 = workspace + "\\" + mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc = arcpy.mapping.MapDocument(mxd2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\VECTOR_QAQC.sde")
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.save()

del mapdoc&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code works as I am switching from one version (SDE.Default) to another version (SDE.QAQC) within the same VECTOR geodatabase.&amp;nbsp; When I try to switch to another SDE geodatabase that contains the same feature class (same owner and feature class name, just different database), it does not work.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd2 = workspace + "\\" + mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc = arcpy.mapping.MapDocument(mxd2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\RASTER_Default.sde")
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.save()

del mapdoc&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any suggestions!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Jul 2011 18:14:38 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2011-07-18T18:14:38Z</dc:date>
    <item>
      <title>Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470350#M36723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to change the data source of an MXD to another SDE geodatabase?&amp;nbsp; I've tried this, but have only been able to get this to work when switching versions within the same SDE geodatabase.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd2 = workspace + "\\" + mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc = arcpy.mapping.MapDocument(mxd2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\VECTOR_QAQC.sde")
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.save()

del mapdoc&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code works as I am switching from one version (SDE.Default) to another version (SDE.QAQC) within the same VECTOR geodatabase.&amp;nbsp; When I try to switch to another SDE geodatabase that contains the same feature class (same owner and feature class name, just different database), it does not work.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd2 = workspace + "\\" + mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc = arcpy.mapping.MapDocument(mxd2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\RASTER_Default.sde")
&amp;nbsp;&amp;nbsp;&amp;nbsp; mapdoc.save()

del mapdoc&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any suggestions!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2011 18:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470350#M36723</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2011-07-18T18:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470351#M36724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It sure is. I used replaceDataSource instead of findAndReplaceWorkspacePaths because it works better with group layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; Attached is a copy of the script I used for all our mxds when we switched to ArcServer 10. It is meant to be run from the python interpreter in an open mxd, and does lots of extra things like copying files from one place to another that we needed so we could deploy this for non-techincal users. You can adapt this for a simpler case (we had a lot of name changes, too) and for looping through mxds in a specified folder; there is no need for the mxd to be open if the parameters are set correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have fun!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2011 14:13:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470351#M36724</guid>
      <dc:creator>RuthEmerick</dc:creator>
      <dc:date>2011-07-19T14:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470352#M36725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Ruth!&amp;nbsp; The 'replaceDataSource' method was exactly what I needed.&amp;nbsp; I was able to get this working with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = workspace = arcpy.GetParameterAsText(0)

env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = workspace + "\\" + mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp; print mxd + " is being processed"
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = mapping.MapDocument(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in mapping.ListDataFrames(mxd, "*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in mapping.ListLayers(mxd, "*", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(arcpy.GetParameterAsText(1), "SDE_WORKSPACE", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Successfully updated data sources"
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()

del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:50:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470352#M36725</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T20:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470353#M36726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do i find the path to the different versions in my SDE ? to use this method ( switch data sources from one version to another)&lt;/P&gt;&lt;P&gt;I only see the SDE name not the path for different versions?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Apr 2017 19:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470353#M36726</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2017-04-05T19:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470354#M36727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/232171"&gt;Joe Head&lt;/A&gt;‌ the version will be controlled through the .sde connection file.&amp;nbsp; If you wan to connect to a different version, create a connection to your enterprise geodatabase &amp;gt; right-click on the connection &amp;gt; Geodatabase Connection Properties.&amp;nbsp; Below is a helpful document:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/manage-data/gdbs-in-db2/connect-geodatabase-version.htm" title="http://desktop.arcgis.com/en/arcmap/latest/manage-data/gdbs-in-db2/connect-geodatabase-version.htm"&gt;Connect to a specific geodatabase version—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Apr 2017 10:10:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470354#M36727</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2017-04-06T10:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470355#M36728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand how to do this with the GUI but I wanted to write a script to change all Layer Data sources within an MXD from Version 1 to version 2 within the same SDE.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:31:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470355#M36728</guid>
      <dc:creator>Lake_Worth_BeachAdmin</dc:creator>
      <dc:date>2017-04-11T20:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Change MXD data sources to another SDE geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470356#M36729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/232171"&gt;Joe Head&lt;/A&gt;‌ once you create the .sde connection file to version 2 using the GUI, have the script point to this .sde connection file and you're all set.&amp;nbsp; You can also create the .sde connection file using the &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-database-connection.htm"&gt;Create Database Connection&lt;/A&gt; tool.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Apr 2017 21:38:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-mxd-data-sources-to-another-sde-geodatabase/m-p/470356#M36729</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2017-04-11T21:38:30Z</dc:date>
    </item>
  </channel>
</rss>

