Can you update query layer connection properties with Python like you can update SDE connection properties?

5326
4
04-08-2015 01:19 PM
MichaelVolz
Esteemed Contributor

I have been using SDE connections for many years and everytime the Oracle Database gets upgraded I need to programmatically change all the SDE connections in the mxds using python scritping.

My organization is now moving towards query layers and I would like know if the same type of update can be done with the query layer connections using python scripting.  If this does exist, where would I find sample code?

4 Replies
MichaelVolz
Esteemed Contributor

Samuel:

Can I at least use python to get the current query layer's properties that I would use to create a replica of the current query layer that would have updated database connection properties (e.g. a newer version of Oracle)?

SamuelTompsett
Occasional Contributor II

Michael,

After looking into this a little more, I stand corrected. You might be able to change the data source  for the query layer using the arcpy.mapping.layer. You should be able to use findandreplaceWorkspacepath. I havent tried this, but it should be possible given the webhelp.

The webhelp for arcpy.mapping is below:

ArcGIS Help 10.1

ChristianWells
Esri Regular Contributor

Hi Michael,

It is possible to do this using arcpy.mapping.Layer():

import arcpy

mxd = arcpy.mapping.MapDocument(<mxdFile>)

lyr = arcpy.mapping.Layer(<queryLayer>)

oldConn = lyr.workspacePath
lyr.findAndReplaceWorkspacePath(<newSDEconn>, <oldSDEconn>)

mxd.save()

Just a note, you won't be able to use the replaceDataSource method for query layers because the dataSource property does not return the name of the tables used in the query layer.

lyr = arcpy.mapping.Layer(<queryLayer>)
print lyr.dataSource

output = u'Database Connections\\ConnectionFile.sde\\SDE.%queryLayer'
VivianMurga
New Contributor

Hi do you have more info on this topic?

0 Kudos