<?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 replaceDataSource connecting to SDE Instance in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30487#M1068</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good morning! I am trying to create a re-pathing script in python but am running into a few kinks. I am hoping that someone can offer some assistance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have right now is ... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

mxd = arcpy.mapping.MapDocument("C:\TEMP\TEST.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == "Database Connections\\SDEConnection.sde\PTD.AIRPORTS":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\SDEConnection.sde\PTD.ap", "SDE_WORKSPACE", "Airports")
mxd.saveACopy(r"C:\TEMP\NEWTEMP.mxd")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried multiple versions in here with varying levels of success. Some don't change anything and just save a new MXD with a broken link. This one is actually changing the path but it's changing it to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;C:\Users\NAME\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\SDEConnection.sde\PTD.ap&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Close .. but I'm trying to connect to our ArcGIS Server instance and NOT a local copy on my machine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ultimately I am wanting the script to run through a list of layers so it can update multiple ones within the same MXD, all who will have new feature class names, which is why I am using the if lyr.dataSource = section... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know what I'm missing? I've been reading through the online documentation but it is very vague when it comes to replaceDataSource ..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Feb 2012 12:15:59 GMT</pubDate>
    <dc:creator>ChristinaGnadinger</dc:creator>
    <dc:date>2012-02-01T12:15:59Z</dc:date>
    <item>
      <title>replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30487#M1068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good morning! I am trying to create a re-pathing script in python but am running into a few kinks. I am hoping that someone can offer some assistance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have right now is ... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

mxd = arcpy.mapping.MapDocument("C:\TEMP\TEST.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == "Database Connections\\SDEConnection.sde\PTD.AIRPORTS":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\SDEConnection.sde\PTD.ap", "SDE_WORKSPACE", "Airports")
mxd.saveACopy(r"C:\TEMP\NEWTEMP.mxd")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried multiple versions in here with varying levels of success. Some don't change anything and just save a new MXD with a broken link. This one is actually changing the path but it's changing it to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;C:\Users\NAME\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\SDEConnection.sde\PTD.ap&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Close .. but I'm trying to connect to our ArcGIS Server instance and NOT a local copy on my machine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ultimately I am wanting the script to run through a list of layers so it can update multiple ones within the same MXD, all who will have new feature class names, which is why I am using the if lyr.dataSource = section... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know what I'm missing? I've been reading through the online documentation but it is very vague when it comes to replaceDataSource ..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 12:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30487#M1068</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2012-02-01T12:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30488#M1069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok .. I'm editing this ... I thought I had this resolved but now I don't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I started using the script in the link below. It works fine for the first layer but doesn't process the rest. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas? I'm still green-ish with python so it's a bit harder for me to find the quirks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/21423-replace-data-sources-script-not-returning-to-for-loop?p=70347&amp;amp;viewfull=1#post70347"&gt;http://forums.arcgis.com/threads/21423-replace-data-sources-script-not-returning-to-for-loop?p=70347&amp;amp;viewfull=1#post70347&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Feb 2012 13:29:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30488#M1069</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2012-02-01T13:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30489#M1070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok. I've been trying to work with the script (below) but having a few dilemmas that I am hoping someone can help me with. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(1) The text file needs the Database Connection name, but it's the 'friendly' name that we use in ArcCatalog, which could be different for every user. Is there a way to instead reference the Server, Service, and Database?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(2) I ran a test where I was trying to replace the contours for a new version. We have contours for multiple counties. What happened was that it ran through the list and only looked for the feature class name and not a match with the owner and feature class name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i.e. I was trying to change PTD.CONTOURS_JEFF to PTD.cn but when it scanned through the connection the script came across BULLITT.cn and assigned it instead of looking for a full match.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(3) Is there a way to tell the script to keep the python / command window open after it processes so we can make sure everything processed ok? When it errors out it closes in a snap and there is no way to see what the message said.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This script is much more in depth to Python than I have gotten so it's taking me a while to troubleshoot this. Any help would be HUGE!!! THANK YOU for reading this and any assistance you can give me! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-

# for test.txt file
# Layername or Source, Layername or SourcePath, Connect To, Featureclass


__doc__ = """ """
import os, sys
import arcpy
from arcpy import env
from optparse import OptionParser

def get_all_files(options, startpath, filter):
&amp;nbsp; """ Build a list of files in a directory, recursively
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (optionally) as default. """
&amp;nbsp; files = []
&amp;nbsp; for filename in os.listdir(startpath):
&amp;nbsp;&amp;nbsp;&amp;nbsp; f = os.path.join(startpath,filename)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isdir(f) and not options.norecurse:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print "Directory found: %s" % (f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = get_all_files(options, f, filter)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if result is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; files += result
&amp;nbsp;&amp;nbsp;&amp;nbsp; if f.upper().endswith(filter.upper()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; files.append(f.upper())
&amp;nbsp; if files is not None and len(files) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; files.sort()
&amp;nbsp; return files

def get_files(options):
&amp;nbsp; """ Get files from command line """
&amp;nbsp; files = options.filelist.upper().split(",")
&amp;nbsp; return files

def changeDataSource(options, filelist):
&amp;nbsp; env.workspace = options.workspace
&amp;nbsp; if filelist is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in filelist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing %s" % (file)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; changed = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(file)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerList = arcpy.mapping.ListLayers(mxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for layer in layerList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if options.listonly:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tLayer %s connects to %s" % (layer.name, layer.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checkIt = inList(layer.name, layer.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if checkIt is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tMatch found for %s" % (layer.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #print os.path.join(env.workspace,checkIt[1][0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if options.force:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # will change the document without workspace/featureclass checks
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.replaceDataSource(checkIt[1][0],options.workspacetype,checkIt[1][1],False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # will only work if a valid workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.replaceDataSource(checkIt[1][0],options.workspacetype,checkIt[1][1],True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; changed = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tDatasource for %s channged to %s" % (layer.name,checkIt[1][1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tCound not change datasource in %s for %s.\n\t%s\n\n\tIf no error number returned, the most likely\n" \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "\tcause is an invalid workspace." % (file,layer.name,e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not options.force:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "\tYou can force it to change with --force option.\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not options.listonly and changed:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Empty file list."
&amp;nbsp; return

def inList(layername, layersource):
&amp;nbsp; global filecontents
&amp;nbsp; for i in filecontents['layer']:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i[0].upper() == layername.upper():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return i
&amp;nbsp; for i in filecontents['source']:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i[0].upper() == layersource.upper():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return i
&amp;nbsp; return None

def readfile(file):
&amp;nbsp; layer = []
&amp;nbsp; source = []
&amp;nbsp; linecnt = 0
&amp;nbsp; contents = open(file,"r")
&amp;nbsp; for line in contents:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if line[0:1] != "#":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; linecnt += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parts = line.split(",")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xx = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xx.append(parts[2].strip())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xx.append(parts[3].strip())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.append(parts[1].strip())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.append(xx)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if parts[0].upper().strip() == "LAYERNAME":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.append(x)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif parts[0].upper().strip() == "SOURCE":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; source.append(x)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Invalid entry: %s" % (parts[0].upper().strip())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del xx
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del x
&amp;nbsp; contents.close()
&amp;nbsp; print "Read %i lines. (excluding comments)" % (linecnt)
&amp;nbsp; return {'layer':layer,'source':source}

def formatstring(string):
&amp;nbsp; layer = []
&amp;nbsp; source = []
&amp;nbsp; parts = string.split(",")
&amp;nbsp; x = []
&amp;nbsp; xx = []
&amp;nbsp; xx.append(parts[2].strip())
&amp;nbsp; xx.append(parts[3].strip())
&amp;nbsp; x.append(parts[1].strip())
&amp;nbsp; x.append(xx)
&amp;nbsp; if parts[0].upper().strip() == "LAYERNAME":
&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.append(x)
&amp;nbsp; elif parts[0].upper().strip() == "SOURCE":
&amp;nbsp;&amp;nbsp;&amp;nbsp; source.append(x)
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Invalid entry: %s" % (parts[0].upper().strip())
&amp;nbsp; del xx
&amp;nbsp; del x
&amp;nbsp; return {'layer':layer,'source':source}

if __name__ == '__main__':
&amp;nbsp; parser = OptionParser(usage='usage: %prog [options]', version='0.1')
&amp;nbsp; parser.add_option('--filelist', action='store', dest='filelist', default=None,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='List of files to process.')
&amp;nbsp; parser.add_option('--dirpath', action='store', dest='dirpath', default='C:\\',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='Path to walk.')
&amp;nbsp; parser.add_option('--filter', action='store', dest='filter', default='.MXD',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='File filter. ie. .MXD')
&amp;nbsp; parser.add_option('--workspace', action='store', dest='workspace', default=None,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='Path to the workspace.')

&amp;nbsp; parser.add_option('--workspacetype', action='store', dest='workspacetype', default="SDE_WORKSPACE",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='Workspace type. Default "SDE_WORKSPACE".')

&amp;nbsp; parser.add_option('--infile', action='store', dest='infile', default=None,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='Input pivot file.')

&amp;nbsp; parser.add_option('--dest', action='store', dest='dest', default=None,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type='string', help='Reassignment string.\n\t' \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ie. "Layername,Artwork,Database Connections\PublicUser.sde,SDE.Artwork"')

&amp;nbsp; #boolean
&amp;nbsp; parser.add_option('--force', action='store_true', dest='force', default=False,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help='Force document update without checking if valid.')
&amp;nbsp; parser.add_option('--listonly', action='store_true', dest='listonly', default=False,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help='Only list the sources found. Do not replace.')
&amp;nbsp; parser.add_option('--norecurse', action='store_true', dest='norecurse', default=False,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; help='Do not recurse directories.')

&amp;nbsp; (options, args) = parser.parse_args()

&amp;nbsp; # this really isn't necessary i do not believe.
&amp;nbsp; if options.workspace is None:
&amp;nbsp;&amp;nbsp;&amp;nbsp; options.workspace = os.environ['APPDATA']+"\ESRI\Desktop10.0\ArcCatalog"

&amp;nbsp; files = get_all_files(options, options.dirpath, options.filter) if options.filelist is None else get_files(options)

&amp;nbsp; if options.infile is not None or options.dest is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if options.infile is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filecontents = readfile(options.infile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filecontents = formatstring(options.dest)

&amp;nbsp; changeDataSource(options, files)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what I've been experimenting with, but the "GIS_LOJIC.sde" is just how I have it referenced on my machine.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Source,Database Connections\GIS_LOJIC.sde\PTD.AIRPORTS_JEFF,Database Connections\GIS_LOJIC.sde,PTD.ap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Source,Database Connections\GIS_LOJIC.sde\PTD.CONTOURS_JEFF,Database Connections\GIS_LOJIC.sde,PTD.cn&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Source,Database Connections\GIS_LOJIC.sde\PTD.HL_LINE_JEFF,Database Connections\GIS_LOJIC.sde,PTD.hl_line&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30489#M1070</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2021-12-10T21:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30490#M1071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Christina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ultimately, what are you trying to do?&amp;nbsp; From your first post it looks like you are trying to replace the feature class 'Airports' in your MXD with another feature class called 'AP'.&amp;nbsp; You can do this 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
env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("C:\TEMP\Airports.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == "Database Connections\\SDEConnection.sde\\LocalData.VECTOR.Airports":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\SDEConnection.sde", "SDE_WORKSPACE", "ap")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "AP"
mxd.saveACopy(r"C:\TEMP\NEW_Airports.mxd")

del mxd&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above code is written for ArcSDE for SQL Server.&amp;nbsp; It will find the layer that is in the LocalData database, owned by the user Vector, and is named "Airports".&amp;nbsp; This is the line:&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG&gt;if lyr.dataSource == "Database Connections\\SDEConnection.sde\\LocalData.VECTOR.Airports":&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next, the replaceDataSource method updates this to the other feature class.&amp;nbsp; I specify the Database Connection (you will not want to reference the new feature class name, only the SDE connection), the workspace type, and the new feature class to change the Airports feature class to.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next line: &lt;/SPAN&gt;&lt;STRONG&gt;lyr.name = "AP"&lt;/STRONG&gt;&lt;SPAN&gt; is simply renaming the layer in the table of contents.&amp;nbsp; Then finally I am saving the MXD to a new MXD.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, when specifying the SDE connection file, be sure to use '\\' instead of '\'.&amp;nbsp; If you use '\', you will need to specify an 'r' in front of the path:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;r"Database Connections\SDEConnection.sde\LocalData.VECTOR.Airports"&lt;/STRONG&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30490#M1071</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T21:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30491#M1072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok. That's the route I started down. The // fixed the Database Connection but I'm still having an issue where it's grabbing the wrong data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As an example our data has&amp;nbsp;&amp;nbsp; BULLITT.bg and PTD.bg .. which are different counties. When the script runs it should be grabbing the PTD.bg but it's seeing the BULLITT.bg first, grabbing that and stopping. It's doing this with all the layers that we have different ones for the different counties.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you know of any way to get past that? It was doing the same thing on the other script too. &lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;BR /&gt;Thank you!! &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this helps, here is what I have so far. &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
env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("C:\TEMP\TEST.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.AIRPORTS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.ap")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Airports"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.BG_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.bg")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Buildings - Jeff Co"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.CONTOURS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.cn")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Contours - Jeff Co"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.CNANNOL_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.cnanno")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Contour Labels - Jeff Co"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.HYDRO_LINES_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.hl")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Water Polygons"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.HL_LINE_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.hl_line")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Water Lines"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.MISC_STRUC_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.ms")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Miscellaneous Structures"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.MISC_TRANS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.mt")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Miscellaneous Transportation"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.ROADS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.rd")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Miscellaneous Structures"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.RAIL_ROADS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.rr")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Railroads - Jeff Co"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.dataSource == "Database Connections\\GIS_LOJIC.sde\\PTD.SPOT_HEIGHTS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.sh")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "Spot Elevations - Jeff Co"

mxd.saveACopy(r"C:\TEMP\NEWTEST.mxd")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30491#M1072</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2021-12-10T21:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30492#M1073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I could not reproduce where the script is grabbing the incorrect data.&amp;nbsp; I tried different scenarios (i.e. connected to the database as a user that has read privileges to all the feature class).&amp;nbsp; Do you have service pack 3 installed for ArcGIS 10?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Feb 2012 15:35:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30492#M1073</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-02-03T15:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30493#M1074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, I have Service Pack 3 on here. The login I'm using for this is the master account too so it has all privileges. It's very weird .. and frustrating &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I could not reproduce where the script is grabbing the incorrect data.&amp;nbsp; I tried different scenarios (i.e. connected to the database as a user that has read privileges to all the feature class).&amp;nbsp; Do you have service pack 3 installed for ArcGIS 10?&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Feb 2012 16:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30493#M1074</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2012-02-03T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30494#M1075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Change your database connection to the PTD user and then execute your script to see if that makes a difference.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Feb 2012 17:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30494#M1075</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-02-03T17:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30495#M1076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You mean change the SDE connection username to PTD? I don't not believe that it is an actively used username here .. we actually pull the data from an outside source and through the transfer process the files are given names / owners to be consistent with what they are using. I'm thinking that if it were only pulling based on the owner then it would not have correctly selected PTD.xxx on the other attempts (it only grabbed the wrong data when we had multiple features with the same feature class name and different owners). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll check to see if it's an actual created account but even if it is that will make this difficult to implement on multiple machines with unique logins on each. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to create a temporary login through the script (if it exists) and then refer back to the previous one afterwards?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 14:14:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30495#M1076</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2012-02-06T14:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30496#M1077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Christina:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your python script, maybe you can use the datasetname to get the full name of the SDE feature class so it differentiates between BULLITT.bg and PTD.bg.&amp;nbsp; You can then use If Then statements to make sure it gets resourced to the correct data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, do you plan on running this script on many mxds at once in a loop?&amp;nbsp; I have been writing similar python scripts where I resource SDE data and it appears there is a memory leak as the memory usage for the script keeps going up until it locks up the computer.&amp;nbsp; I am currently working with ESRI Technical Support to resolve this particular issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please let me know if you need any clarification or additional information from my response.&amp;nbsp; Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2012 13:21:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30496#M1077</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2012-02-13T13:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30497#M1078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the suggestion!!! I am going to try to look into this today. I've been detoured temporarily. I'll have to look at the comparison in Python between SDE feature class and datasetname .. I'm still learning some of the conventions within Python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess once I get the script up and running I may survey the users to see how many scripts they have that will need altering. I haven't actually gotten that far down the list, however if it's a memory issue then I may just keep it simple. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tested doing this imported as a model and did not have any better success in that route. It seems like I always want to write the scripts that have one impossible hang up ... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Christina:&lt;BR /&gt;&lt;BR /&gt;In your python script, maybe you can use the datasetname to get the full name of the SDE feature class so it differentiates between BULLITT.bg and PTD.bg.&amp;nbsp; You can then use If Then statements to make sure it gets resourced to the correct data.&lt;BR /&gt;&lt;BR /&gt;In addition, do you plan on running this script on many mxds at once in a loop?&amp;nbsp; I have been writing similar python scripts where I resource SDE data and it appears there is a memory leak as the memory usage for the script keeps going up until it locks up the computer.&amp;nbsp; I am currently working with ESRI Technical Support to resolve this particular issue.&lt;BR /&gt;&lt;BR /&gt;Please let me know if you need any clarification or additional information from my response.&amp;nbsp; Thank you.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 13:13:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30497#M1078</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2012-02-17T13:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: replaceDataSource connecting to SDE Instance</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30498#M1079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is what I was trying the last time I worked on it, but this did not work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you mention using If Then are you thinking that it should be before or after the replace data? I was working on the hopes that if it mis-assigned it to BULLITT.cn in the replacedatasource I could change it afterwards, which did not work. I figured it was a long shot but worth trying! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
from arcpy import mapping
env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("C:\TEMP\TEST.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.datasetName == "PTD.CONTOURS_JEFF":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource("Database Connections\\GIS_LOJIC.sde", "SDE_WORKSPACE", "PTD.cn")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "BULLITT" in lyr.name:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.name = "PTD" + lyr.name.split(".")[2]

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
mxd.saveACopy(r"C:\TEMP\NEWTEST.mxd")

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:13:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/replacedatasource-connecting-to-sde-instance/m-p/30498#M1079</guid>
      <dc:creator>ChristinaGnadinger</dc:creator>
      <dc:date>2021-12-10T21:13:23Z</dc:date>
    </item>
  </channel>
</rss>

