#------------------------------------------------------------------------------- # Name: ULIMS Perfomance Management # Purpose: Script scheduled in windows scheduler used to perfom enteprise geodatabase tuning # # Author: dmuthami # # Created: 17/03/2015 # Copyright: (c) dmuthami 2015 # Licence: <your licence> #------------------------------------------------------------------------------- import os, sys import logging import arcpy import traceback from arcpy import env from datetime import datetime def ulimsPerfomanceManagement(): #Set-up logging logger = logging.getLogger('ulimsAutomation') try: #Export to text file# currentDate = datetime.now().strftime("-%y-%m-%d_%H-%M-%S") # Current time #Set-up some error logging code. cat_logfile = os.path.join(os.path.dirname("__file__"), 'cat_logfile' + str(currentDate)+'.log') #cat_logfile = r"C:\DAVID-MUTHAMI\GIS Data\Namibia ULIMS\Scripts" + "\\"+str(currentDate)+'.log' hdlr = logging.FileHandler(cat_logfile) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.INFO) # Import the toolbox containing the model. This toolbox # has an alias of "ulimsAutomation" #Run model in a toolbox in a folder # model optimizes enterprise geodatabase from SQL Server #arcpy.ImportToolbox(r"C:\DAVID-MUTHAMI\GIS Data\Namibia ULIMS\Scripts\ULIMS_System.tbx","ulimsAutomation") #Run model hosted on SQL Server enterprise GDB to optimize enterprise geodatabase arcpy.ImportToolbox(r"Database Connections\sde@localhost@ulims_publication.sde","ulimsAutomation") # Run the model. # arcpy.ULIMSPerformanceManagement_ulimsAutomation() msg = "Performance tuning complete" print msg logger.info(msg) except: ## Return any Python specific errors and any error returned by the geoprocessor ## tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\n ulimsPerfomanceManagement() Function : Traceback Info:\n" + tbinfo + "\nError Info:\n " + \ str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n" +\ "Line {0}".format(tb.tb_lineno) msgs = "Geoprocessing Errors :\n" + arcpy.GetMessages(2) + "\n" ##Add custom informative message to the Python script tool arcpy.AddError(pymsg) #Add error message to the Python script tool(Progress dialog box, Results windows and Python Window). arcpy.AddError(msgs) #Add error message to the Python script tool(Progress dialog box, Results windows and Python Window). ##For debugging purposes only ##To be commented on python script scheduling in Windows _log print pymsg logger.info(pymsg) print "\n" +msgs logger.info(msgs) def main(): pass if __name__ == '__main__': main() #Run perfomance management module ulimsPerfomanceManagement()
Solved! Go to Solution.
Thanks to Esri support for providing answer to the problem.
See attached full code with correction.
Erroneous line of code reads like:
arcpy.ImportToolbox(r"Database Connections\sde@localhost@ulims_publication.sde","ulimsAutomation")
Corrected line of code reads:
##The below line code is when the toolbox containing the model is stored/hosted on SQL Server enterprise GDB
arcpy.ImportToolbox(r"D:\GIS\Connection Files\Live Site\sde@172.24.0.47@ulims_gis.sde\ulims_gis.SDE.System_Admin","ulimsAutomation")
Psst! Posting your code with syntax highlighting is appreciated!
Thanks Blake. Your post was very helpful and i have applied the python formatting. The code should now be readable and clear.
Line 53 is the cause of the error. however, if i comment line 53 and uncomment line 47 the script runs flawlessly. This implies the problem occurs when when the model is stored in the enterprise geodatabase or any type of geodatabase used by Esri. The code only works if the model is in a toolbox stored in a folder. Let me if their is a solution.
Thanks to Esri support for providing answer to the problem.
See attached full code with correction.
Erroneous line of code reads like:
arcpy.ImportToolbox(r"Database Connections\sde@localhost@ulims_publication.sde","ulimsAutomation")
Corrected line of code reads:
##The below line code is when the toolbox containing the model is stored/hosted on SQL Server enterprise GDB
arcpy.ImportToolbox(r"D:\GIS\Connection Files\Live Site\sde@172.24.0.47@ulims_gis.sde\ulims_gis.SDE.System_Admin","ulimsAutomation")