ANA_SNIRH

Load SQL View on ArcMap, using Python

Discussion created by ANA_SNIRH on Feb 23, 2018

I want to add a sql view, generated in slq server, on ArcMap document, through python script.

 

My sql view has this fields:

 

My script is:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

lyr = arcpy.mapping.Layer(r'Database Connections\xxxxx.sde\xxxx.dbo.Lay1')

arcpy.mapping.AddLayer(df,lyr)

 

This script load lyr on ArcMap temporaly, but when I want to acces to Attribute table, see this error:

 

I don´t know how to indicate to python, wich field from Lay1 contain oid, in my case OBJECTID field.

 

I guess your help, thanks.

Outcomes