2

Is there any way to get version of a layer loaded using arcpy.MakeFeatureLayer_management in arcpy with mssql server connection. There are tools that be used for several types of version related tasks like arcpy.ChangeVersion_management, arcpy.CreateVersionedView_management etc. but i want to know is there any way to know version of the that temporary layer in arcpy.

I tried Listing ArcSDE versions using ArcPy? but it gives all the version in a sde connection- but i want to know specifically with which version layer is loaded.So i do not want arcpy.ListVersions(r'Database Connections\MSSQLSERVER.sde')

I tried arcpy.Describe but all in vain.

Below is the pseudocode-

arcpy.CreateDatabaseConnection_management("path","Test1.sde","SQL_SERVER","instance","DATABASE_AUTH","user","pass","SAVE_USERNAME","sde__my","#","TRANSACTIONAL","DBO.Test1","#")

Above line does not change the version to "DBO.Test1" if i run as above but if i run the gui tool it works perfectly so i need to check if version changed.


mywrk = r"path\Test1.sde"
fc_cor1 = r'path\Test1.sde\sde__my.DBO.FIPS2900\sde__my.DBO.testfc_1'
fc_cor2 = r'path\Test1.sde\sde__my.DBO.FIPS2900\sde__my.DBO.testfc'


arcpy.MakeFeatureLayer_management(fc_cor1,'fc1')
arcpy.MakeFeatureLayer_management(fc_cor2,'fc2')

Now i want to know if version of 'fc1' and 'fc2' is DBO.Test1 otherwise change as below-

try:
    arcpy.ChangeVersion_management("fc1","TRANSACTIONAL","DBO.Test1")
    arcpy.ChangeVersion_management("fc2","TRANSACTIONAL","DBO.Test1")
except:
    pass

demo

I am using ArcGIS 10.1 and MSSQL Server 2012

2

You need to obtain the map layer object first -

fl = arcpy.MakeFeatureLayer_management(fc,"out_fl")
map_layer = fl.getOutput(0)
map_layer.serviceProperties['Version']
>>> u'sde.DEFAULT'

which has the serviceProperties property - a dictionary containing all the information related to the connection including, but not limited to the version name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.