<?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: replaceDataSource error in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292532#M3083</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm getting the exact same error when trying to use replaceDataSource on SDE feature classes...you are not alone.&amp;nbsp; I haven't figured out a work around for this yet so any help would be appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Nov 2013 23:19:48 GMT</pubDate>
    <dc:creator>DanJoyce1</dc:creator>
    <dc:date>2013-11-21T23:19:48Z</dc:date>
    <item>
      <title>replaceDataSource error</title>
      <link>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292530#M3081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script that replaces layers in an mxd file. It checks for the existence of the SDE layer and if it exists, writes it into the mxd file. If it doesn't exist, it writes a different SDE layer into the mxd file. Everything works until I use the arcpy.Exists statement. If I remove this statement, the replaceDataSource command works. If I keep the statement, it errors out with the extremely helpful error message "Value Error: Layer: Unexpected error". I'm at my wit's end with this one. Here's my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import sys, string, os, datetime, arcpy
from time import *

today = datetime.date.today()
wrkspc = r"Database Connections\Connection to HABSOS fluke pg.sde"

#&amp;nbsp; update sea surface temperature project file
print "Updating Sea Surface Temperature Project"
mxd = arcpy.mapping.MapDocument(r"d:\ArcServer_Maps\ModelRuns_AMSEAS\AMSEAS_WaterTemp_Hindcasts.mxd")
new_mxd = r"d:\ArcServer_Maps\ModelRuns_AMSEAS\updates\AMSEAS_WaterTemp_Hindcasts.mxd"
if os.path.isfile(new_mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(new_mxd)

i = 1
while i &amp;lt; 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp; previous = today - datetime.timedelta(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; newDate = previous.isoformat()
&amp;nbsp;&amp;nbsp;&amp;nbsp; dateString = newDate.replace('-','')
&amp;nbsp;&amp;nbsp;&amp;nbsp; AMSEAS_SST = wrkspc + "\AMSEAS_SST_" + dateString
&amp;nbsp;&amp;nbsp;&amp;nbsp; sdeLayer = "AMSEAS_SST_" + dateString
&amp;nbsp;&amp;nbsp;&amp;nbsp; templateLayer = "AMSEAS_SST_Template"
&amp;nbsp;&amp;nbsp;&amp;nbsp; nameString = "Day " + str(i) + " - " + dateString
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrID = i - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(AMSEAS_SST):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Found SST layer %s .. Will update project" % AMSEAS_SST
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd)[lyrID]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(wrkspc, "SDE_WORKSPACE", sdeLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = nameString
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Didn't find SST layer %s ... Will update project with SST template" % AMSEAS_SST
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.ListLayers(mxd)[lyrID]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(wrkspc, "SDE_WORKSPACE", templateLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = nameString
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del lyr
&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1

mxd.saveACopy(new_mxd)
del mxd, new_mxd
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is the error I get when I leave the arcpy.Exists call:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "D:\ArcServer_Maps\ModelRuns_AMSEAS\test.py", line 28, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr.replaceDataSource(wrkspc, "SDE_WORKSPACE", sdeLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return fn(*args, **kw)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;File "D:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 585, in replaceDataSource&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ValueError: Layer: Unexpected error&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please help!!!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:04:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292530#M3081</guid>
      <dc:creator>BetsySchenck-Gardner</dc:creator>
      <dc:date>2021-12-11T14:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource error</title>
      <link>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292531#M3082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you print out the variable AMSEAS_SST?&amp;nbsp; I believe this should be a feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm wondering if you would need to make a connection to the SDE database with this connection string to really check for its existence.&amp;nbsp; The ESRI Help sample at:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004p000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004p000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does not show how to use python to check an SDE feature class, so I'm thinking it might not be as straightforward as checking the existence of a feature class in a personal or file geodatabase.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 15:40:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292531#M3082</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2013-04-02T15:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource error</title>
      <link>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292532#M3083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm getting the exact same error when trying to use replaceDataSource on SDE feature classes...you are not alone.&amp;nbsp; I haven't figured out a work around for this yet so any help would be appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Nov 2013 23:19:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/replacedatasource-error/m-p/292532#M3083</guid>
      <dc:creator>DanJoyce1</dc:creator>
      <dc:date>2013-11-21T23:19:48Z</dc:date>
    </item>
  </channel>
</rss>

