def ConnectToServer(args, argTup): """ * Connect to target T-SQL server and database. If testing LOCAL: * Drop existing rows with test FileDate. * Open DYETL.WebApi, post file using postargs.json. * Run DYETL.Service to insert data into target table. * Check local log file, throw exception if issue occurred with DYETL.Service. If not testing STG: * Drop existing rows with test FileDate. """ try: interface = TSQLInterface(argTup[1], argTup[2]) except Exception as ex: print("Could not connect to %s::%s" % (argTup[1], argTup[2])) print("Reason: %s" % str(ex)) input('Press enter to exit.') os._exit(0) if args['testetlargs']['testmode'] == 'LOCAL': # Open DynamicETL.WebApi and post test ETL job: print("Loading ETL %s test job to WebAPI at" % args['testetlargs']['postargs']['subject']) print(args['fixedargs']['webapipath']) try: loader = ETLJobLoader(args['fixedargs']['webapipath'], args['fixedargs']['dynamicetlservicepath'], args['fixedargs']['logpath'], args['fixedargs']['webapiurl']) loader.RunETL(args['testetlargs']['postargs']) # Check log file for issues, throw exception if occurred: except Exception as ex: print('ETL could not be run. Reason: %s' % str(ex)) input('Press enter to exit.') os._exit(0) elif args['testetlargs']['testmode'] != 'STG' and args['testetlargs'][ 'removeprevfiledate']: # Remove data with filedate from server: print('Removing data with [%s] %s from %s::%s::%s' % (argTup[4], argTup[0], argTup[1], argTup[2], argTup[3])) try: query = "DELETE FROM [%s] WHERE [%s] = '%s';" % ( argTup[3], argTup[4], argTup[0]) interface.Execute(query) except Exception as ex: print( 'Could not delete data with [%s] %s from %s::%s::%s.' % argTup[4], argTup[1], argTup[2], argTup[3]) print('Reason: %s' % str(ex)) input('Press enter to exit.') os._exit(0) return interface
def pulldata(): interface = TSQLInterface('nj1sql13', 'Metrics') query = "EXEC dbo.AdHocReport_StuDurnin_DeskVolumes '2020-05-29'" results = interface.Execute(query, True) results.to_csv("StuDurninResults.csv")