Invalid expression error, but expression works in different environment

630
2
05-21-2018 11:13 AM
by Anonymous User
Not applicable

Hello,

I have a script that I created that automates a join and field calculation process across multiple feature classes. The script works when I test locally, but when I move it to another test environment, I receive an Invalid Expression error. Wondering if this could potentially be a permissions issue, or what could be causing this. The only differences between environments are the connection paths.

Here is the error message:

Traceback (most recent call last):
File "C:\Users\vueworks\Desktop\MDCETL\Testing_Logging.py", line 64, in <module>
vwfcin = arcpy.MakeTableView_management(sde+"\\"+vwfc, vwt)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 7047, in MakeTableView
raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (MakeTableView).

And the script.

import arcpy, sys, string, os, subprocess, logging

def getLogger():
    # Logs to console and log file
    logger = logging.getLogger()
    formatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s]  %(message)s")
    fileHandler = logging.FileHandler("MDC_ViewtoGIS_Automated.log")
    fileHandler.setFormatter(formatter)
    logger.addHandler(fileHandler)
    consoleHandler = logging.StreamHandler()
    consoleHandler.setFormatter(formatter)
    logger.addHandler(consoleHandler)
    logger.setLevel(logging.INFO)
    return logger

log = getLogger()
     
gdb = r'C:\Users\vueworks\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\MDC_ETL.sde'

gdbsdeds = "MDC_ETL.DBO."

sde = r'C:\Users\vueworks\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\MDCTest_1025.sde'

sdeds = "MDCTest_1025.dbo.ViewETL_FacilityType_"

gdbee = gdbsdeds+"Exterior_Electrical"
gdbem = gdbsdeds+"Exterior_Mechanical"
gdbfs = gdbsdeds+"Facility_Site"
gdbfp = gdbsdeds+"Fish_Production"
gdbg = gdbsdeds+"Generic"
gdbhm = gdbsdeds+"Hydrology_Management"
gdbr = gdbsdeds+"Range"
gdbswm = gdbsdeds+"Storm_Water_Management"
gdbwm = gdbsdeds+"Wastewater_Management"
gdbwc = gdbsdeds+"Water_Conveyance"

gca = vca = "Conservation_Area_Name"
gcn = vcn = "Conservation_Area_Number"
gn = vn = "Network"
gan = van = "Asset_Name"

gfi = "Field_ID"
gai = "Asset_ID"
gt1n = "Tier_1_System_Name"
gt1t = "Tier_1_System_Type"
gt2n = "Tier_2_Major_Subsystem_Name"
gt2t = "Tier_2_Major_Subsystem_Type"
gt3n = "Tier_3_Minor_Subsystem_Name"
gt3t = "Tier_3_Minor_Subsystem_Type"

vfi = "FieldID"
vai = "AssetID"
vt1n = "Tier_1_Name"
vt1t = "Tier_1_Type"
vt2n = "Tier_2_Name"
vt2t = "Tier_2_Type"
vt3n = "Tier_3_Name"
vt3t = "Tier_3_Type"

gdfc = gdbsdeds+"Phase_Converter_Exterior"
gdfcin = arcpy.MakeFeatureLayer_management(gdb+"\\"+gdbee+"\\"+gdfc, gdfc)

vwfc = sdeds+"PhaseConverterExterior"
vwfcin = arcpy.MakeTableView_management(sde+"\\"+vwfc, vwfc)

slct = gdfc+"."+gai+" IS NULL OR ("+gdfc+"."+gai+" <> "+vwfc+"."+vai+")"

try:
    arcpy.AddJoin_management(gdfc, gfi, vwfc, vfi)
    arcpy.SelectLayerByAttribute_management(gdfc, "NEW_SELECTION", slct)
    arcpy.CalculateField_management(gdfc, gdfc+"."+gai, "["+vwfc+"."+vai+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gca, "["+vwfc+"."+vca+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gcn, "["+vwfc+"."+vcn+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gn, "["+vwfc+"."+vn+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt1n, "["+vwfc+"."+vt1n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt1t, "["+vwfc+"."+vt1t+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt2n, "["+vwfc+"."+vt2n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt2t, "["+vwfc+"."+vt2t+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gt3n, "["+vwfc+"."+vt3n+"]", "VB", "")
    arcpy.CalculateField_management(gdfc, gdfc+"."+gan, "["+vwfc+"."+van+"]", "VB", "")
except:
    log.error(arcpy.GetMessages()) # log everything as ERROR (but should preserve order of messages)
     #log.warning(arcpy.GetMessages(1)) # log warning messages as WARN
    #log.error(arcpy.GetMessages(2))# log error messages as ERROR

arcpy.RemoveJoin_management(gdfc)
arcpy.SelectLayerByAttribute_management(gdfc, "CLEAR_SELECTION", "")
0 Kudos
2 Replies
MichaelMiller2
Occasional Contributor III

You might want to rethink the paths for gdb and sde, maybe create/copy the database connection to a shared location.

0 Kudos
by Anonymous User
Not applicable

I won't have control of the paths moving forward. For testing, I guess I can put them where ever, but once this is moved to another server, the default paths will be what I have to work with. I know named user paths can potentially introduce complications from what others have told me. Just confusing because the paths on my local machine are essentially the same, just with me as the user instead of a generic one, and the expression works fine.

0 Kudos