Convert LayerFiles connection from Application Server TO Direct(ArcPY)

1687
4
02-22-2016 04:15 AM
User35489
Occasional Contributor III

Greetings All,

I have a folder containing various Layer files, Vector and Raster. Vector layers are connecting to SDE through Application Server Connect.
I want to write a script which help me identify Vector Layers from folder and change their connection from 'Application Server' type to 'Direct Connect'

Can you please help me with the best way i can change their connection type from 'Application Server' type to 'Direct Connect'

Environment: ArcGIS 10.1/10.3 Desktop, ArcSDE 10.1, RHEL 6, Oracle 11g

With Best Regards

-AS

Tags (2)
0 Kudos
4 Replies
by Anonymous User
Not applicable

Dear Abdullah

you can use the serviceProperties property of your layer files ( Layer—Help | ArcGIS for Desktop  ) and, once selected the layers whose datasource you want to change, use the replaceDataSource  method  for modifing the datasource (e.g. to a new direct connect .sde file).

That makes sense?

Regards

Jesús de Diego

0 Kudos
User35489
Occasional Contributor III

Alarcon,

Thanks for your input.

(Below code for mxd) serviceProperties is working fine with layers(not with broken data source) within .mxd. But as i have multiple layer files stored on disk. I would like to check the properties of .lyr files in folder and repair their data sources. Any suggestion is highly appreciated.

Thanks

import arcpy, os

mxd = arcpy.mapping.MapDocument(r"Path to mxd")

for lyr in arcpy.mapping.ListLayers(mxd):

    if lyr.supports("SERVICEPROPERTIES"):

        servProp = lyr.serviceProperties

        print "Layer name:" + lyr.name

        print "-----------------------------------------------------"

        if lyr.serviceProperties["ServiceType"] != "SDE":

            print "Service Type: " + servProp.get('ServiceType', 'N/A')

            print "    URL:        " + servProp.get('URL', 'N/A')

            print "    Connection:  " + servProp.get('Connection', 'N/A')

            print "    Server:      " + servProp.get('Server', 'N/A')

            print "    Cache:      " + str(servProp.get('Cache', 'N/A'))

            print "    User Name:  " + servProp.get('UserName', 'N/A')

            print "    Password:    " + servProp.get('Password', 'N/A')

            print ""

        else:

            print "Service Type: " + servProp.get('ServiceType', 'N/A')

            print "    Database:      " + servProp.get('Database', 'N/A')

            print "    Server:        " + servProp.get('Server', 'N/A')

            print "    Service:        " + servProp.get('Service', 'N/A')

            print "    Version:        " + servProp.get('Version', 'N/A')

            print "    User name:      " + servProp.get('UserName', 'N/A')

            print "    Authentication: " + servProp.get('AuthenticationMode', 'N/A')

            print ""    

del mxd

0 Kudos
by Anonymous User
Not applicable

You an try using ListFiles. Take a look at the below example.

Regards

Jesus de Diego Alarcón

import os
import arcpy

arcpy.env.workspace = "c:/temp"

# Copy each file with a .csv extension to a dBASE file
for lyr_file in arcpy.ListFiles("*.lyr"😞

     if lyr_file.supports("SERVICEPROPERTIES"):

     ......

     ......

0 Kudos
User35489
Occasional Contributor III

Can you please share any working script, if any?

Thanks

0 Kudos