Hello Everybody! Please I really need help with this python script. The objective of the script is to list all the mxd files in the specified folder, identify all the layers within the mxd that were sourced from my old SDE database server, and then change the layer source to my new SDE database server. In other words, the main purpose of the script is to do a bulk data source change for all the layers in my mxd files So far the script is able to list all the mxds and the paths of the layer sources but it is not changing the data sources for layers in my SDE as needed import arcpy, os, getpass newServer = "TNR-GISSQL19-P" user = getpass.getuser() #user_dir = os.path.join(u'C:\\Users\\', user) user_dir = u'Y:\\VIEWERS\\T' ### this specifies the directory containing the mxd files os.chdir(user_dir) ############create logfile############ logfile = open("logfile_for_Shade_upgrade.txt", "w") ## creates a logfile print>>logfile, "User's home directory: %r" % user_dir ############create mxdList############ mxdList =  for dirpath,_,filenames in os.walk(user_dir): for name in filenames: if name.endswith('.mxd'): mapdoc= os.path.join(dirpath, name) mxdList.append(mapdoc) print>>logfile, "------MXD List:------" ############print MXDs to logfile############ for mapdoc in mxdList: print>>logfile, mapdoc for file in mxdList: print>>logfile, "---Searching for SDE connections in: %r" % file filePath = os.path.join(user_dir, file) mxd = arcpy.mapping.MapDocument(filePath) for lyr in arcpy.mapping.ListLayers(mxd): try: if lyr.supports("dataSource"): try: ## if lyr.supports("SERVICEPROPERTIES") and lyr.serviceProperties['ServiceType'] == u'SDE' and 'Server' in lyr.serviceProperties and lyr.serviceProperties['Server'] == u'Frogmouth': if lyr.supports("SERVICEPROPERTIES") and lyr.serviceProperties['ServiceType'] == u'SDE' and lyr.serviceProperties['Server'] == u'frogmouth': ## print>>logfile, lyr.serviceProperties print>>logfile, "layer uses Frogmouth" try: serverName = lyr.serviceProperties[u'Server'] databaseName = lyr.serviceProperties[u'Database'] if not databaseName.endswith('.sde'): databaseName += '.sde' print>>logfile, "Updating: %r, %r:" %(lyr.serviceProperties['Server'], lyr.serviceProperties['Database']) layerName = lyr.datasetName print>>logfile, "Layer name: %r" % layerName if lyr.supports("workspacePath"): find = lyr.workspacePath ## herein lies the problem, some lyr.workspacePath do not exist print>>logfile, "Current path: %r" % find replacePath = os.path.join(user_dir+"\\AppData\\Roaming\\ESRI\\Desktop10.7\\ArcCatalog\\",os.path.os.path.basename(newServer)+"_"+databaseName) print>>logfile, "New Path: %r" % replacePath mxd.replaceWorkspaces(find,"SDE_WORKSPACE",replacePath,"SDE_WORKSPACE",False) print>>logfile, "****************%r has been updated successfully" % lyr.datasetName else: print>>logfile, "!!!!!!Connection path not valid! Layer not updated" except: print>>logfile, "Unknown error occurred (level 0)." else: print>>logfile, "Layer does not use a Vultur SDE connection: %r, %r" %(lyr.datasetName, lyr.dataSource) except: print>>logfile, "Unknown error occurred (level 1)." else: print>>logfile, "Layer is basemap and does not need to be updated." except: print>>logfile, "Unknown error occurred (level 2)." #mxd.save() ## test first with this commented out, because otherwise you will have to revert to Frogmouth if you want to re-test logfile.close() print "Completed."
... View more
I recently replaced my existing data server with a new server thus a new server name and path. My existing data server is named skunk while my new server is tesclon. I need to reroute all the datasources in my over 300 mxd files that points to skunk to now point to Tesclone. The script has been modified and some print statements were used to capture what is going on. It is able to access the new data path and the old datapath, it is also able to list the mxd files and datasource path but it seems not able to execute the "find and replace datasource" So i really need help at this juncture. #Tell the script which data path needs to be updated
oldPath = r"\\skunk\GIS\Projects\Irene"
#Tell the script what the new data path is
newDataPath = r"\\isilonc1\dept\tnr\skunk\GIS\projects\Irene"
#### Stop editing the code here ####
#use arcpy to list all of the mxd files
list_dir = 
CountList = 
MapList = 
list_dir = os.listdir(path)
count = 0
for paths, dirctory, files in os.walk(path):
for file in files:
if file.endswith(extension): # eg: '.mxd'
for m in MapList:
count += 1
mxd = arcpy.mapping.MapDocument(m)
#-------------Use below to call the function----------------#
mxdList = ListMXDSources(path=r"\\skunk\GIS\Projects\Irene",extension=".mxd")
#print the total number of mxd files
if len(mxdList) == 0:
print "There are no mxd files found in this directory."
if len(mxdList) == 1:
print "There is "+str(len(mxdList))+" mxd file found in this directory."
if len(mxdList) > 1:
print "There are "+str(len(mxdList))+" mxd files found in this directory."
#set the count of the mxds to 0
count = 0
errorCount = 0
#starting the loop to check for each of the mxds
for mxds in mxdList:
#set the mxd to the workspace with the mxd files
mxd = arcpy.mapping.MapDocument(mxds)
for lyr in arcpy.mapping.ListLayers(mxd):
theData = lyr.dataSource
dataSourceCheck = lyr.dataSource[:-8]
if dataSourceCheck == oldPath:
count += 1
except Exception as e:
print "The following error has occured:"
print "Because there was an error, you should try re-running the script."
errorCount += 1
successCount = count-errorCount
print "The conversion process has finished and "+str(successCount)+" file(s) have been replaced."
... View more
Rex, " When the origin ArcGIS Server was configured, it looks like admin access through Web Adapter was disabled... so I'm wondering if this is blocking the script from accessing some required contents through the server/arcgis/ Web Adapter endpoints" I'm thinking this could be a problem, Is there a way you can enable this admin access again and run the script once more because you really need an username and password with admin rights. If it fails then we would know that the issue might most probably be on the script. I'm not sure if you have read the documentation provided by the original developers of that script. I will try and past some of the information here for you. The script has 12 parameters and here are the descriptions and requirements. I'm hoping by the time you go through the document below you will be able to identify the issue but if you still are not able to resolve it, we can move on to the next level of critically looking at what you have on your modified script Functionality The script uses twelve parameters. Only one of them is optional:  Input Server Name (string) The host name of the origin server. Typically a single name or fully qualified server, such as myServer.esri.com  Input Server Port (string) The port number for the origin ArcGIS Server. Typically this is 6080. If you have a web adapter installed with your GIS Server and have the REST Admin enabled you can connect using the web servers port number.  Input Server User (long) Administrative username.  Input Server Password (string) Administrative password.  Service Type (string) The type of the service to migrate.  Services (Multiple Value) One or more services to perform an action on. The tool will autopopulate with a list of services when the first 5 parameters are entered. Service names must be provided in the <ServiceName>.<ServiceType> style.  Output Server Name (string) The host name of the end server. Typically a single name or fully qualified server, such as myServer.esri.com  Output Server Port (long) The port number for the final ArcGIS Server. Typically this is 6080. If you have a web adapter installed with your GIS Server and have the REST Admin enabled you can connect using the web servers port number.  Output Server User (string) Administrative username.  Output Server Password (string) Administrative password.  (optional) Folder (string) A destination folder different from the original/s one/s can be introduced.  sysTemp (string) A folder where the services sources are going to be stored. The script uses the username and the password to connect to the original and destination server with a generatetoken action. After accessing to the original server, all services are listed. When the user selects the services to migrate and fills all the parameters the process starts. Firstly, a copy of the selected service's sources is made, this copy is placed in the sysTemp path. After that, all the service's properties are read and modified in the copy done in the sysTemp path. The tool checks if in the destination server exists a folder with the same name as the original one, or with the name defined as a parameter. If not the folder is created. Once the folder is created the tool publish the service using the copied sources. Is important to notice that if the service has special permission (cannot access to it everyone), also this permission is set in the new service. The procedure is: In case the role exists in the destination server: Only the access permission is assigned to the service. In case the role does not exists in the destination server: The role is created with the same characteristics of the original one, the role privileges are assigned to the role and the users within that role are transferred. Note: When the users are copied from one server to another it is not possible to transfer the password of the user so is set by default.
... View more
If you are using ArcGIS Server 10.6 or 10.7 this simple option might work for you as it did work for me recently. I needed to move our maps services from ArcGIS 10.6 single server to ArcGIS 10.7 federated with Portal.. The script posted here did not work for me, though it worked perfectly well when i was moving from 10.5.1 standalone server environment to 10.6.1 standalone server environment. If you are getting a Network Error, Just check the ports of the servers. I did experience that error when i was working with the stand alone server , if the ports are incorrect, you will get that error So in my new situation what i did was to simply upgrade the ArcGIS 10.6.2 standalone server to ArcGIS 10.7, so i now have both servers running the same ArcGIS Server version which is 10.7. Then to move the map services across, I use the export and import tools in the Admin server and it worked very easily for me. I do not know the ArcGIS Server environment you are working with but it is good to note that the script we are discussing above works only for Standalone server environment and cannot work for a federated server environment
... View more
I recently upgraded my single site ArcGIS Enterprise 10.6.1 to Federated ArcGIS Enterprise 10.7 using the export and import tools on Server Admin page. I noticed that after the import and export task, all the cached map services lost the cached tiles. Please can someone show me how i can import the tiles from the single unfederated server into my federated server Question 2. I am able to see all the imported map services on the ArcGIS Server site but I not able to see these map services when i connect to the ArcGIS Server on ArcCatalog. The folders are showing empty when viewed on ArcCatalog Please I really need help with these. See sample screenshots attached
... View more
Hi Vince Please do you still have the link to this FTP. I tried it but it is not working. I have a need to INSERT, UPDATE, and DELETE rows in non-versioned layers in ArcSDE. I want to see if your 'C' utility here can provide me with the solution i need. Thanks Irene
... View more
Hi Jonathan, I have been able to resolve the socket error issue by simply getting my IT department to change the port of the server from port 6443 to port 6080. Now I am able to push the map services and folders over to the new server but unfortunately, it now comes up with another error of not able to publish the service due to errors found during the analysis. (it does not specify what exactly the error is) Please can you think of what could be the problem here. Your contribution will be highly appreciated. Please see error below. Start Time: Tue Apr 30 09:41:50 2019 ERROR 999999: Error executing function. Unidentified Error Failed to execute (UploadServiceDefinition). Failed at Tue Apr 30 09:41:50 2019 (Elapsed Time: 0.02 seconds) Failed to publish. ** Service 'CWPP//FlamMap_Input_Fuel.MapServer' published successfully.
... View more
Have you tried the ShortList storymap template. That should solve your problem because it provides you the opportunity to customize your story map with pictures and a webmap. But you would need to arrange your data to mactch the excel template. you can follow the steps below. I got it from Esri support though i am still working on my own story map because i need it to populate data dynamically from my SDE database Navigate to the WebMap and share as a StoryMap Template Download Template: Unzip the downloaded file. Once unzipped, you'll see a folder that contains all the necessary files. See the Readme file for instructions on deploying and configuring your application. Deploy the Web application to your Web server. Copy the application files to your Web server. Configure the Web application. You can make simple changes to the Web application, like providing a different title, without having any programming experience. Minimally, you'll need to reference the map ID to display your map in the Web application. Follow the instructions in the Readme file to do this. You will also need to choose the second option of 'Yes, use them as-is' to reference the SQL database you edit. Managing the shortlist will be a little different but it should create a dynamic relationship between your data and the StoryMap can will automatically reference any edits.
... View more
Please I would like to know if there is a new and easier way to achieve the transfer of map services from one ArcGIS server machine to another A rc GIS server machine. I have over 400 map services to transfer. Some two years back I was able to achieve this using the discomap.ServiceTransferTool t hat i found on this forum and the transfer was made from Version 10.4 to 10.5. Now we upgraded to a full ArGIS Enterprise environment 10.6.2 (ArcGIS Server, Portal for ArcGIS and Datastore) unfortunately the tool has failed and every effort have proved abortive. I keep getting this "No JSON object could be decoded" error. I am not good with JSON and I couldn't figure out what it is that is generating this errort. I would really appreciate helps and contributions from anyone here. thanks Please see attached screenshots of the tool and the error I got when executed. ** Service 'Irene//CIP_Project.MapServer' information read successfully. Now transfering... (5 steps) pathInitial line 653: E:\arcgisserver\directories\arcgissystem\arcgisinput\Irene\CIP_Project.MapServer\extracted\v101\CIP_Project.msdpathInitial line 655: E$\arcgisserver\directories\arcgissystem\arcgisinput\Irene\CIP_Project.MapServer\extracted\v101\CIP_Project.msdpathInitial line 657: \\Hamiltonpool\E$\arcgisserver\directories\arcgissystem\arcgisinput\Irene\CIP_Project.MapServer\extracted\v101\CIP_Project.msd msdPath line 659: \\Hamiltonpool\E$\arcgisserver\directories\arcgissystem\arcgisinput\Irene\CIP_Project.MapServer\extracted\v101\CIP_Project.msd simpleServiceName line 668: CIP_Project finalServiceName line 672: Irene//CIP_Project.MapServer Failed script TransferServices... Traceback (most recent call last): File "Y:\TOOLS\Server Tools\discomap.ServiceTransferTool-master\TransferServices3.py", line 1280, in <module> transferMapServices(fromServerName, fromServerPort, fromAdminUser, fromAdminPass, serviceList, toServerName, toServerPort, toAdminUser, toAdminPass, serviceType, workspace, newFolder, overwrite, workFolder) File "Y:\TOOLS\Server Tools\discomap.ServiceTransferTool-master\TransferServices3.py", line 621, in transferMapServices serviceExists = isServicePresent(toServerName, str(toServerPort), toAdminUser, toAdminPass, simpleServiceName, folderName, "") File "Y:\TOOLS\Server Tools\discomap.ServiceTransferTool-master\TransferServices3.py", line 101, in isServicePresent token = gentoken(server, port, adminUser, adminPass) File "Y:\TOOLS\Server Tools\discomap.ServiceTransferTool-master\TransferServices3.py", line 26, in gentoken token = json.loads(urllib.urlopen(url + "?f=json", query_string).read()) File "C:\Python27\ArcGIS10.5\Lib\urllib.py", line 89, in urlopen return opener.open(url, data) File "C:\Python27\ArcGIS10.5\Lib\urllib.py", line 215, in open return getattr(self, name)(url, data) File "C:\Python27\ArcGIS10.5\Lib\urllib.py", line 350, in open_http h.endheaders(data) File "C:\Python27\ArcGIS10.5\Lib\httplib.py", line 1038, in endheaders self._send_output(message_body) File "C:\Python27\ArcGIS10.5\Lib\httplib.py", line 882, in _send_output self.send(msg) File "C:\Python27\ArcGIS10.5\Lib\httplib.py", line 844, in send self.connect() File "C:\Python27\ArcGIS10.5\Lib\httplib.py", line 821, in connect self.timeout, self.source_address) File "C:\Python27\ArcGIS10.5\Lib\socket.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): IOError: [Errno socket error] [Errno 11001] getaddrinfo failed Failed to execute (TransferServices). Failed at Mon Apr 01 09:08:16 2019 (Elapsed Time: 1.84 seconds)
... View more