AnsweredAssumed Answered

How to add query table to map in python

Question asked by don.morrison on Sep 17, 2019
Latest reply on Feb 26, 2020 by don.morrison

I have an SQL Server view that at I want to include in my ArcGIS server's REST endpoint as a table. I'm able to do it manually using ArcMap - it appears to create a query table when I drag the view onto the table of contents. How can I do this in python?


Currently I go through this sequence

  1. Start with a blank mxd file: mxd_template_obj = arcpy.mapping.MapDocument(blank_template_fn)
  2. Get the dataframe: df = ListDataFrames(mxd_template_obj)[0]
  3. Create the query table (according to the documentation is creates a TableView): arcpy.MakeQueryTable_management(db_view, table_view_name, ....)
  4. Convert it to a TableView object: table_view = arcpy.mapping.TableView(table_view_name)
  5. Add it to the map: arcpy.mapping.AddTableView(df, table_view)
  6. Save the map: mxd_template_obj.saveACopy(<mxd_file_name>)


It appears to generate a good mxd file - I can go into ArcMap and everything looks correct, but when I try to stage it for publishing I get this error:


ExecuteError: ERROR 001272: Analyzer errors were encountered (codes = 33, 33)

Standalone table's data source is not supported


I suspect that my step 4 is wrong - once I have the query table I need to do something else to get it into the map correctly but I'm not sure what that is.