Jump to content

ADODB.Connection issue


Recommended Posts

Post your code in code block (the <> thing) to get some help.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Developers

@chkrishna,

Could you please stop posting all these questions in different OLD topics and use this thread and:

  • Post your script source you are having issues with in a codebox.
  • Explain what you are trying to do and isn't working.

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=include\icons\edit.ico
#AutoIt3Wrapper_Outfile=bin\Load_Profile_Scenario.exe
#AutoIt3Wrapper_Res_Comment=Allows you to simulate load on the DMS system through database calls.
#AutoIt3Wrapper_Res_Description=Program to simulate load on the DMS system.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.57
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <String.au3>
#include <include\MailSlot.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <include\cmdLine.au3>
#include <MsgBoxConstants.au3>



OnAutoItExitRegister('_Exit')

; Read passed in values or use defaults
_CmdLine_Parse('--', 'testLength|whereClause|crewStatus|etor|dispComments|gpsUpdates|referrals|outDetail|rptDetail|amiMeterPing|jocRpt1|jocRpt2|srpRpt|relRpt|forceUp|verify|restore', '_CmdLine_Error')
$iTestLength   = CmdLine('testLength')
$iWhereClause  = CmdLine('whereClause')
$iCrewStatus   = CmdLine('crewStatus')
$iEtor         = CmdLine('etor')
$iDispComments = CmdLine('dispComments')
$iGpsUpdates   = CmdLine('gpsUpdates')
$iReferrals    = CmdLine('referrals')
$iOutDetail    = CmdLine('outDetail')
$iRptDetail    = CmdLine('rptDetail')
$iAmiMeterPing = CmdLine('amiMeterPing')
$iJocRpt1      = CmdLine('jocRpt1')
$iJocRpt2      = CmdLine('jocRpt2')
$iSrpRpt       = CmdLine('srpRpt')
$iRelRpt       = CmdLine('relRpt')
$iForceUp      = CmdLine('forceUp')
$iVerify       = CmdLine('verify')
$iRestore      = CmdLine('restore')
;**********************************************
GLOBAL Const $ORACLE_HOME= EnvGet("ORACLE_HOME")
Global Const $DBSERVICE="VVVVV"
Global Const $ASTORM_ID="VVVV"
Global Const $ASTORM_PWD="VVVV"



;**********************************************
; Create mailslot for child scripts to send status updates
Global Const $sMailSlotName = "\\.\mailslot\loadprofileupdates"
Global Const $sMailSlotControlName = "\\.\mailslot\control"

Global $hMailSlot = _MailSlotCreate($sMailSlotName)
If @error Then
    MsgBox(48 + 262144, "MailSlot", "Failed to create new account!" & @CRLF & "Probably one using that 'address' already exists.")
    Exit
EndIf

Global $cMailSlot = _MailSlotCreate($sMailSlotControlName)
If @error Then
    MsgBox(48 + 262144, "MailSlot", "Failed to create new account!" & @CRLF & "Probably one using that 'address' already exists.")
    Exit
EndIf

; Register adlib function to periodically check mailslot for messages and update monitor listview (10 seconds)
AdlibRegister('checkMailSlot', 10000)
AdlibRegister('checkChildScripts', 30000)

Opt("GUIResizeMode", $GUI_DOCKAUTO)
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Initialize a COM error handler
GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND')

; GUI variables
Global $loggingEdit = 9999, $startTimeArray[1], $statusLabel = 9999, $crewapi, $startScenarioButton = 9999
Global $dbSetupGUI = 9999, $astormDBUsernameInput, $astormDBPasswordInput, $dbConnectInput, $dbCancelButton = 9999, $dbSaveButton = 9999
Global $fileMenuAbort, $fileMenuExit

; GUI Input Box variables
Global $testLengthInput, $whereClauseInput, $crewStatusRateInput, $etorRateInput, $dispatcherCommentRateInput, $crewGPSRateInput, $referralRateInput, $outageDetailRateInput, $troubleRptRateInput, $amiMeterPingRateInput
Global $jocReport1Input, $jocReport2Input, $srpReportInput, $reliabilityReportInput, $forceUpstreamRateInput, $verifyRateInput, $restoreRateInput

; Database variables
Global $astormDBUser, $astormDBPass, $astormDBName

; Child process variables
Global $crewStatusPID = '', $etorPID = '', $dispatcherCommentPID = '', $crewGPSPID = '', $referralPID = '', $outageDetailPID = '', $troubleRptDetailPID = '', $amiMeterPingPID = ''
Global $jocRpt1PID = '', $jocRpt2PID = '', $srpRptPID = '', $reliabilityRptPID = '', $forceUpstreamPID = '', $verifyPID = '', $restorePID

; Rate variables
Global $crewStatusRate = 0, $etorRate = 0, $dispatcherCommentRate = 0, $crewGPSRate = 0, $referralRate = 0, $outageDetailRate = 0, $troubleRptRate = 0, $amiMeterPingRate = 0
Global $jocRpt1Rate = 0, $jocRpt2Rate = 0, $srpRptRate = 0, $reliabilityRptRate = 0, $forceUpstreamRate = 0, $verifyRate = 0, $restoreRate = 0

; Misc
Global $pathArray[1][2]
Global $initialDir = ''
Global $fInterrupt
Global $runningFlag = 0

; Save update scripts in temp dir and delete when program close
DirCreate(@TempDir & '\performance_scripts\')
ConsoleWrite(@TempDir & '\performance_scripts\' & @CRLF)
FileInstall('bin\loadsimulator.conf', @TempDir & '\performance_scripts\loadsimulator.conf', 1)
FileInstall('bin\crew_status_updates.exe', @TempDir & '\performance_scripts\crew_status_updates.exe', 1)
FileInstall('bin\ETOR_Updates.exe', @TempDir & '\performance_scripts\ETOR_Updates.exe', 1)
FileInstall('bin\dispatcher_comments_updates.exe', @TempDir & '\performance_scripts\dispatcher_comments_updates.exe', 1)
FileInstall('bin\crew_gps_Updates.exe', @TempDir & '\performance_scripts\crew_gps_Updates.exe', 1)
FileInstall('bin\referrals.exe', @TempDir & '\performance_scripts\referrals.exe', 1)
FileInstall('bin\outage_detail_callup.exe', @TempDir & '\performance_scripts\outage_detail_callup.exe', 1)
FileInstall('bin\trouble_rpt_detail_callup.exe', @TempDir & '\performance_scripts\trouble_rpt_detail_callup.exe', 1)
FileInstall('bin\AMI_Meter_Ping.exe', @TempDir & '\performance_scripts\AMI_Meter_Ping.exe', 1)
FileInstall('bin\JOC_report_1.exe', @TempDir & '\performance_scripts\JOC_report_1.exe', 1)
FileInstall('bin\JOC_report_2.exe', @TempDir & '\performance_scripts\JOC_report_2.exe', 1)
FileInstall('bin\srp_report.exe', @TempDir & '\performance_scripts\srp_report.exe', 1)
FileInstall('bin\reliability_report.exe', @TempDir & '\performance_scripts\reliability_report.exe', 1)
FileInstall('bin\force_outage_upstream.exe', @TempDir & '\performance_scripts\force_outage_upstream.exe', 1)
FileInstall('bin\verify_outage.exe', @TempDir & '\performance_scripts\verify_outage.exe', 1)
FileInstall('bin\restore_outage.exe', @TempDir & '\performance_scripts\restore_outage.exe', 1)

mainGui()

Func mainGui()
    #Region ### START Koda GUI section ### Form=c:\users\uszaand\documents\github\performance-scripts\load scenario\loadsimulatorgui.kxf
    Global $loadSimulatorGUI = GUICreate("ADMS / OMS Storm Simulator", 1205, 656, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
    $fileMenu = GUICtrlCreateMenu("&File")
    $fileMenuLoadScenario = GUICtrlCreateMenuItem("Load Scenario", $fileMenu)
    $fileMenuSaveScenario = GUICtrlCreateMenuItem("Save Scenario", $fileMenu)
    $fileMenuSeperator = GUICtrlCreateMenuItem("", $fileMenu)
    $fileMenuAbort = GUICtrlCreateMenuItem("Abort", $fileMenu)
    GUICtrlSetState($fileMenuAbort, $GUI_DISABLE) ; Only enabled while running
    $fileMenuSeperator2 = GUICtrlCreateMenuItem("", $fileMenu)
    $fileMenuExit = GUICtrlCreateMenuItem("Exit", $fileMenu)
    $configMenu = GUICtrlCreateMenu("&Config")
    $crewapi = GUICtrlCreateMenuItem("Database Setup", $configMenu)
    ; Check for loadsimulator.conf and default to the one that is there.
    If FileExists(@WorkingDir & '\loadsimulator.conf') Then
        GUICtrlSetState($crewapi, $GUI_CHECKED)
    EndIf
    $testLengthLabel = GUICtrlCreateLabel("Test Length (Minutes):", 16, 12, 360, 20)
    $testLengthInput = GUICtrlCreateInput("", 16, 37, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $whereClauseLabel = GUICtrlCreateLabel("Where Clause for Outage Select Statement:", 160, 12, 360, 20)
    $whereClauseInput = GUICtrlCreateInput("rest_done = '_' and time_stamp < sysdate", 160, 37, 1031, 24, $GUI_SS_DEFAULT_INPUT)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetTip(-1, "This query is performed once only at the start of the scenario.  'order by dbms_random.value' will be appended to the end.")
    $crewStatusRateLabel = GUICtrlCreateLabel("Crew Status / Hr:", 16, 81, 360, 20)
    $crewStatusRateInput = GUICtrlCreateInput("", 16, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $etorRateLabel = GUICtrlCreateLabel("ETOR / Hr:", 160, 81, 360, 20)
    $etorRateInput = GUICtrlCreateInput("", 160, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $dispatcherCommentRateLabel = GUICtrlCreateLabel("Disp. Comments / Hr:", 315, 81, 360, 20)
    $dispatcherCommentRateInput = GUICtrlCreateInput("", 315, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $crewGPSRateLabel = GUICtrlCreateLabel("GPS updates / Hr:", 470, 81, 360, 20)
    $crewGPSRateInput = GUICtrlCreateInput("", 470, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $referralRateLabel = GUICtrlCreateLabel("Referrals / Hr:", 625, 81, 360, 20)
    $referralRateInput = GUICtrlCreateInput("", 625, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $outageDetailRateLabel = GUICtrlCreateLabel("Outage Detail / Hr:", 780, 81, 360, 20)
    $outageDetailRateInput = GUICtrlCreateInput("", 780, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $troubleRptRateLabel = GUICtrlCreateLabel("Trouble Rpt Detail / Hr:", 935, 81, 360, 20)
    $troubleRptRateInput = GUICtrlCreateInput("", 935, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $amiMeterPingRateLabel = GUICtrlCreateLabel("AMI Meter Ping / Hr:", 1090, 81, 360, 20)
    $amiMeterPingRateInput = GUICtrlCreateInput("", 1090, 106, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $jocReport1Label = GUICtrlCreateLabel("JOC Rpt 1 / Hr:", 16, 156, 360, 20)
    $jocReport1Input = GUICtrlCreateInput("", 16, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $jocReport2Label = GUICtrlCreateLabel("JOC Rpt 2 / Hr:", 160, 156, 360, 20)
    $jocReport2Input = GUICtrlCreateInput("", 160, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $srpReportLabel = GUICtrlCreateLabel("SRP Rpt / Hr:", 315, 156, 360, 20)
    $srpReportInput = GUICtrlCreateInput("", 315, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $reliabilityReportLabel = GUICtrlCreateLabel("Reliability Rpt / Hr:", 470, 156, 360, 20)
    $reliabilityReportInput = GUICtrlCreateInput("", 470, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $forceUpstreamLabel = GUICtrlCreateLabel("Force Upstream / Hr:", 625, 156, 360, 20)
    $forceUpstreamRateInput = GUICtrlCreateInput("", 625, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $verifyLabel = GUICtrlCreateLabel("Verify / Hr:", 780, 156, 360, 20)
    $verifyRateInput = GUICtrlCreateInput("", 780, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $restoreLabel = GUICtrlCreateLabel("Restore / Hr:", 935, 156, 360, 20)
    $restoreRateInput = GUICtrlCreateInput("", 935, 181, 100, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
    $startScenarioButton = GUICtrlCreateButton("Start Scenario", 16, 226, 1170, 50)
    $logging = GUICtrlCreateGroup("Logging", 16, 286, 1170, 329)
    $loggingEdit = GUICtrlCreateEdit("", 32, 311, 1140, 289, BitOR($GUI_SS_DEFAULT_EDIT,$ES_NOHIDESEL,$ES_READONLY))
    GUICtrlSetLimit(-1, 10000000)
    GUICtrlSetData(-1, "")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    ; Set fields based on command line options
    GUICtrlSetData($testLengthInput, $iTestLength)
;~  If $iWhereClause <> '' Then
;~      GUICtrlSetData($whereClauseInput, $iWhereClause)
;~  EndIf
    GUICtrlSetData($crewStatusRateInput, $iCrewStatus)
    GUICtrlSetData($etorRateInput, $iCrewStatus)
    GUICtrlSetData($dispatcherCommentRateInput, $iCrewStatus)
    GUICtrlSetData($crewGPSRateInput, $iCrewStatus)
    GUICtrlSetData($referralRateInput, $iCrewStatus)
    GUICtrlSetData($outageDetailRateInput, $iCrewStatus)
    GUICtrlSetData($troubleRptRateInput, $iCrewStatus)
    GUICtrlSetData($amiMeterPingRateInput, $iCrewStatus)
    GUICtrlSetData($jocReport1Input, $iCrewStatus)
    GUICtrlSetData($jocReport2Input, $iCrewStatus)
    GUICtrlSetData($srpReportInput, $iCrewStatus)
    GUICtrlSetData($reliabilityReportInput, $iCrewStatus)
    GUICtrlSetData($forceUpstreamRateInput, $iCrewStatus)
    GUICtrlSetData($verifyRateInput, $iCrewStatus)
    GUICtrlSetData($restoreRateInput, $iCrewStatus)

    While 1
        $nMsg = GUIGetMsg(1) ; Use advancedparameter to get array
        Switch $nMsg[1] ; check which GUI sent message
            Case $loadSimulatorGUI
                Switch $nMsg[0] ; now check for the messages to current gui only
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $fileMenuExit
                        Exit
                    Case $crewapi
                        If Not WinExists('Database Connection Info') Then
                            If databaseSetup() = 1 Then
                                ContinueLoop
                            EndIf
                        Else
                            WinActivate('Database Connection Info')
                        EndIf
                    Case $startScenarioButton
                        runScenario()
                    Case $fileMenuLoadScenario
                        Local $loadFile, $loadArray[1]
                        $loadFile = FileOpenDialog('Load from file: ', @WorkingDir, 'All (*.*)')
                        If @error Then ContinueLoop
                        _FileReadToArray($loadFile, $loadArray)
                        GUICtrlSetData($testLengthInput, $loadArray[1])
                        GUICtrlSetData($crewStatusRateInput, $loadArray[2])
                        GUICtrlSetData($etorRateInput, $loadArray[3])
                        GUICtrlSetData($dispatcherCommentRateInput, $loadArray[4])
                        GUICtrlSetData($crewGPSRateInput, $loadArray[5])
                        GUICtrlSetData($referralRateInput, $loadArray[6])
                        GUICtrlSetData($outageDetailRateInput, $loadArray[7])
                        GUICtrlSetData($troubleRptRateInput, $loadArray[8])
                        GUICtrlSetData($amiMeterPingRateInput, $loadArray[9])
                        GUICtrlSetData($jocReport1Input, $loadArray[10])
                        GUICtrlSetData($jocReport2Input, $loadArray[11])
                        GUICtrlSetData($srpReportInput, $loadArray[12])
                        GUICtrlSetData($reliabilityReportInput, $loadArray[13])
                        GUICtrlSetData($forceUpstreamRateInput, $loadArray[14])
                        GUICtrlSetData($verifyRateInput, $loadArray[15])
                        GUICtrlSetData($restoreRateInput, $loadArray[16])

                    Case $fileMenuSaveScenario
                        Local $saveFile, $saveArray[16]
                        ConsoleWrite('inside save scenario' & @LF)
                        $saveFile = FileOpenDialog('Save to file: ', @WorkingDir, 'All (*.*)')
                        ConsoleWrite('selected file?' & @LF)
                        If @error Then ContinueLoop
                        $saveArray[0] = Number(GUICtrlRead($testLengthInput))
                        $saveArray[1] = Number(GUICtrlRead($crewStatusRateInput))
                        $saveArray[2] = Number(GUICtrlRead($etorRateInput))
                        $saveArray[3] = Number(GUICtrlRead($dispatcherCommentRateInput))
                        $saveArray[4] = Number(GUICtrlRead($crewGPSRateInput))
                        $saveArray[5] = Number(GUICtrlRead($referralRateInput))
                        $saveArray[6] = Number(GUICtrlRead($outageDetailRateInput))
                        $saveArray[7] = Number(GUICtrlRead($troubleRptRateInput))
                        $saveArray[8] = Number(GUICtrlRead($amiMeterPingRateInput))
                        $saveArray[9] = Number(GUICtrlRead($jocReport1Input))
                        $saveArray[10] = Number(GUICtrlRead($jocReport2Input))
                        $saveArray[11] = Number(GUICtrlRead($srpReportInput))
                        $saveArray[12] = Number(GUICtrlRead($reliabilityReportInput))
                        $saveArray[13] = Number(GUICtrlRead($forceUpstreamRateInput))
                        $saveArray[14] = Number(GUICtrlRead($verifyRateInput))
                        $saveArray[15] = Number(GUICtrlRead($restoreRateInput))
                        _FileWriteFromArray($saveFile, $saveArray)

                EndSwitch
            Case $dbSetupGUI
                Switch $nMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($dbSetupGUI)
                    Case $dbCancelButton
                        GUIDelete($dbSetupGUI)
                    Case $dbSaveButton
                        ; Check that all fields are entered
                        Local $inputArray[3]
                        $inputArray[0] = GUICtrlRead($astormDBUsernameInput)                        
                        $inputArray[1] = GUICtrlRead($astormDBPasswordInput)
                        $inputArray[2] = GUICtrlRead($dbConnectInput)
                        If $inputArray[0] = '' Or $inputArray[1] = '' Or $inputArray[2] = '' Then
                            MsgBox(48, 'Error', 'All fields are required.  Please try again.')
                        Else
                            ; save config to working directory
                            _FileWriteFromArray(@WorkingDir & '\loadsimulator.conf', $inputArray)
                            $astormDBUser = $inputArray[0]
                            $astormDBPass = $inputArray[1]
                            $astormDBName = $inputArray[2]
                            GUIDelete($dbSetupGUI)
                        EndIf

                EndSwitch

        EndSwitch
    WEnd
EndFunc   ;==>mainGui

Func databaseSetup()
    $oraPath=$ORACLE_HOME
    $oraPath = $oraPath & '\network\admin\tnsnames.ora'
    ConsoleWrite($oraPath & @CRLF)
    Dim $tnsNames
    _FileReadToArray($oraPath, $tnsNames)
    $indexes = _ArrayFindAllEx($tnsNames, '* =', True, '(*', True)
    $dbNames = StringTrimRight($tnsNames[$indexes[0]], StringLen($tnsNames[$indexes[0]]) - StringInStr($tnsNames[$indexes[0]], '=') + 1)
    $dbNames = $DBSERVICE
    For $i = 1 To UBound($indexes) - 1
        $dbNames &= '|' & StringTrimRight($tnsNames[$indexes[$i]], StringLen($tnsNames[$indexes[$i]]) - StringInStr($tnsNames[$indexes[$i]], '=') + 1)
    Next

    $dbSetupGUI = GUICreate("DatabaseInfo", 388, 298, 228, 169)
    $GroupBox1 = GUICtrlCreateGroup("", 10, 1, 365, 238)
    $astormDBUsernameLabel = GUICtrlCreateLabel("Astorm Username:", 20, 29, 210, 29)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $astormDBUsernameInput = GUICtrlCreateInput("", 20, 61, 345, 24)
    $astormDBPasswordLabel = GUICtrlCreateLabel("Astorm Password:", 20, 93, 210, 29)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $astormDBPasswordInput = GUICtrlCreateInput("", 20, 125, 345, 24, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
    $dbConnectLabel = GUICtrlCreateLabel("DB Connection String:", 20, 157, 269, 29)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $dbConnectInput = GUICtrlCreateCombo("", 20, 189, 345, 24, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $dbSaveButton = GUICtrlCreateButton("&Save", 80, 250, 92, 31)
    GUICtrlSetState($dbSaveButton, $GUI_DEFBUTTON)
    $dbCancelButton = GUICtrlCreateButton("&Cancel", 199, 250, 93, 31)
    GUICtrlSetData($dbConnectInput, $dbNames, StringTrimRight($tnsNames[$indexes[0]], StringLen($tnsNames[$indexes[0]]) - StringInStr($tnsNames[$indexes[0]], '=') + 1))

    ; Check for current conf file
    $confFile = FileOpen(@WorkingDir & '\loadsimulator.conf')
    If $confFile <> -1 Then
        Local $inputArray[4]
        ; read in values and set input boxes
        _FileReadToArray(@WorkingDir & '\loadsimulator.conf', $inputArray)
        GUICtrlSetData($astormDBUsernameInput, $inputArray[1])
        GUICtrlSetData($astormDBPasswordInput, $inputArray[2])
        GUICtrlSetData($dbConnectInput, $inputArray[3])
    EndIf
    FileClose($confFile)

    GUISetState(@SW_SHOW)
EndFunc   ;==>databaseSetup

Func runScenario()
    ; Flag to indicate that child scripts are running
    Global $runningFlag = 1
    ; File to log all status updates
    Global $logFile =  'C:\Logs\Load_Scenario_' & StringReplace(StringReplace(StringReplace(_NowCalc(), '/', '_'), ' ', '_'), ':', '_') & '.txt'

    ; Initialize timer for test length
    $startTime = TimerInit()
    ; Reset fInterrupt
    $fInterrupt = 0

    $confFile = FileOpen(@WorkingDir & '\loadsimulator.conf')
    If $confFile = -1 Then
        ; File failed to open
        logToEdit($loggingEdit, 'Conf file does not exist.  Create one by clicking Config -> Crew API - Database Setup and fill in parameters.' & @CRLF)
        MsgBox(48, 'Error', 'Conf file does not exist.  Create one by clicking Config -> Crew API - Database Setup and fill in parameters.')
        Return
    Else
        Local $inputArray[4]
        ; read in values
        If $astormDBUser = '' Or $astormDBPass = '' Or $astormDBName = '' Then
            logToEdit($loggingEdit, 'Inputs to database setup incomplete.  Reading from Conf file instead' & @CRLF)
            _FileReadToArray(@WorkingDir & '\loadsimulator.conf', $inputArray)
            $astormDBUser =$ASTORM_ID
            $astormDBPass = $ASTORM_PWD
            $astormDBName =$DBSERVICE
        EndIf
        logToEdit($loggingEdit, @CRLF & 'Database Username: ' & $astormDBUser & @CRLF & 'Database Password: ' & ' (Encrypted)' & @CRLF & 'Database Name: ' & $astormDBName & @CRLF)
    EndIf

    ; Make sure length and where clause were specified
    $testLength = Number(GUICtrlRead($testLengthInput))
    $whereClause = GUICtrlRead($whereClauseInput)
    If $testLength <= 0 Then
        MsgBox(48, 'Error', 'Test length was not specified.  Please enter and try again.')
        Return
    ElseIf $whereClause = '' Then
        MsgBox(48, 'Error', 'Where clause was not specified.  Please enter and try again.')
        Return
    EndIf

    ; Make sure rate was entered, if not return
    $crewStatusRate = Number(GUICtrlRead($crewStatusRateInput))
    $etorRate = Number(GUICtrlRead($etorRateInput))
    $dispatcherCommentRate = Number(GUICtrlRead($dispatcherCommentRateInput))
    $crewGPSRate = Number(GUICtrlRead($crewGPSRateInput))
    $referralRate = Number(GUICtrlRead($referralRateInput))
    $outageDetailRate = Number(GUICtrlRead($outageDetailRateInput))
    $troubleRptRate = Number(GUICtrlRead($troubleRptRateInput))
    $amiMeterPingRate = Number(GUICtrlRead($amiMeterPingRateInput))
    $jocRpt1Rate = Number(GUICtrlRead($jocReport1Input))
    $jocRpt2Rate = Number(GUICtrlRead($jocReport2Input))
    $srpRptRate = Number(GUICtrlRead($srpReportInput))
    $reliabilityRptRate = Number(GUICtrlRead($reliabilityReportInput))
    $forceUpstreamRate = Number(GUICtrlRead($forceUpstreamRateInput))
    $verifyRate = Number(GUICtrlRead($verifyRateInput))
    $restoreRate = Number(GUICtrlRead($restoreRateInput))
    If ($crewStatusRate = 0 And $etorRate = 0 And $dispatcherCommentRate = 0 And $crewGPSRate = 0 And $referralRate = 0 And $outageDetailRate = 0 _
            And $troubleRptRate = 0 And $amiMeterPingRate = 0 And $jocRpt1Rate = 0 And $jocRpt2Rate = 0 And $srpRptRate = 0 And $reliabilityRptRate = 0 _
            And $forceUpstreamRate = 0 And $verifyRate = 0 And $restoreRate = 0) Then
        MsgBox(48, 'Error', 'No rates were not specified.  Please enter and try again.')
        Return
    Else
        ; Disable all buttons
        GUICtrlSetState($startScenarioButton, $GUI_DISABLE)
        GUICtrlSetData($startScenarioButton, 'Running Scenario')
        GUICtrlSetState($fileMenuExit, $GUI_DISABLE)
        GUICtrlSetState($crewapi, $GUI_DISABLE)
        GUICtrlSetState($fileMenuAbort, $GUI_ENABLE)
        GUICtrlSetState($testLengthInput, $GUI_DISABLE)
;~      GUICtrlSetState($whereClauseInput, $GUI_DISABLE)
        GUICtrlSetState($crewStatusRateInput, $GUI_DISABLE)
        GUICtrlSetState($etorRateInput, $GUI_DISABLE)
        GUICtrlSetState($dispatcherCommentRateInput, $GUI_DISABLE)
        GUICtrlSetState($crewGPSRateInput, $GUI_DISABLE)
        GUICtrlSetState($referralRateInput, $GUI_DISABLE)
        GUICtrlSetState($outageDetailRateInput, $GUI_DISABLE)
        GUICtrlSetState($troubleRptRateInput, $GUI_DISABLE)
        GUICtrlSetState($amiMeterPingRateInput, $GUI_DISABLE)
        GUICtrlSetState($jocReport1Input, $GUI_DISABLE)
        GUICtrlSetState($jocReport2Input, $GUI_DISABLE)
        GUICtrlSetState($srpReportInput, $GUI_DISABLE)
        GUICtrlSetState($reliabilityReportInput, $GUI_DISABLE)
        GUICtrlSetState($forceUpstreamRateInput, $GUI_DISABLE)
        GUICtrlSetState($verifyRateInput, $GUI_DISABLE)
        GUICtrlSetState($restoreRateInput, $GUI_DISABLE)
        If $crewStatusRate <> 0 Then
            $crewStatusThroughPut = $crewStatusRate / 3600 ; rate in updates / sec
            ; start crew status update script with specified rate
            ; Send throughput as well as database connection info
            $crewStatusPID = Run(@TempDir & '\performance_scripts\crew_status_updates.exe ' & $crewStatusThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $etorRate <> 0 Then
            $etorThroughPut = $etorRate / 3600 ; rate in updates / sec
            ; start etor update script with specified rate
            ; Send throughput as well as database connection info
            $etorPID = Run(@TempDir & '\performance_scripts\ETOR_Updates.exe ' & $etorThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $dispatcherCommentRate <> 0 Then
            $dispatcherCommentThroughPut = $dispatcherCommentRate / 3600 ; rate in updates / sec
            ; start crew comment update script with specified rate
            ; Send throughput as well as database connection info
            $dispatcherCommentPID = Run(@TempDir & '\performance_scripts\dispatcher_comments_updates.exe ' & $dispatcherCommentThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $crewGPSRate <> 0 Then
            $crewGPSThroughPut = $crewGPSRate / 3600 ; rate in updates / sec
            ; start etor update script with specified rate
            ; Send throughput as well as database connection info
            $crewGPSPID = Run(@TempDir & '\performance_scripts\crew_gps_updates.exe ' & $crewGPSThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $referralRate <> 0 Then
            $referralThroughPut = $referralRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $referralPID = Run(@TempDir & '\performance_scripts\referrals.exe ' & $referralThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $outageDetailRate <> 0 Then
            $outageDetailThroughPut = $outageDetailRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $outageDetailPID = Run(@TempDir & '\performance_scripts\outage_detail_callup.exe ' & $outageDetailThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $troubleRptRate <> 0 Then
            $troubleRptThroughPut = $troubleRptRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $troubleRptDetailPID = Run(@TempDir & '\performance_scripts\trouble_rpt_detail_callup.exe ' & $troubleRptThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $amiMeterPingRate <> 0 Then
            $amiMeterPingThroughPut = $amiMeterPingRate / 3600 ; rate in updates / sec
            ; start ami meter ping script with specified rate
            ; Send throughput as well as database connection info
            $amiMeterPingPID = Run(@TempDir & '\performance_scripts\AMI_Meter_Ping.exe ' & $amiMeterPingThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $jocRpt1Rate <> 0 Then
            $jocRpt1Throughput = $jocRpt1Rate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $jocRpt1PID = Run(@TempDir & '\performance_scripts\JOC_report_1.exe ' & $jocRpt1Throughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $jocRpt2Rate <> 0 Then
            $jocRpt2Throughput = $jocRpt2Rate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $jocRpt2PID = Run(@TempDir & '\performance_scripts\JOC_report_2.exe ' & $jocRpt2Throughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $srpRptRate <> 0 Then
            $srpRptThroughput = $srpRptRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $srpRptPID = Run(@TempDir & '\performance_scripts\srp_report.exe ' & $srpRptThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $reliabilityRptRate <> 0 Then
            $reliabilityRptThroughput = $reliabilityRptRate / 3600 ; rate in updates / sec
            ; qstart referral script with specified rate
            ; Send throughput as well as database connection info
            $reliabilityRptPID = Run(@TempDir & '\performance_scripts\reliability_report.exe ' & $reliabilityRptThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $forceUpstreamRate <> 0 Then
            $forceUpstreamThroughput = $forceUpstreamRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $forceUpstreamPID = Run(@TempDir & '\performance_scripts\force_outage_upstream.exe ' & $forceUpstreamThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $verifyRate <> 0 Then
            $verifyThroughput = $verifyRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $verifyPID = Run(@TempDir & '\performance_scripts\verify_outage.exe ' & $verifyThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
        If $restoreRate <> 0 Then
            $restoreThroughput = $restoreRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $restorePID = Run(@TempDir & '\performance_scripts\restore_outage.exe ' & $restoreThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
        EndIf
    EndIf


    Do
        Sleep(1000)
    Until $fInterrupt = 1 Or TimerDiff($startTime) > $testLength * 60 * 1000

    ; Kill update scripts
    ProcessClose($crewStatusPID)
    ProcessClose($etorPID)
    ProcessClose($dispatcherCommentPID)
    ProcessClose($crewGPSPID)
    ProcessClose($referralPID)
    ProcessClose($outageDetailPID)
    ProcessClose($troubleRptDetailPID)
    ProcessClose($amiMeterPingPID)
    ProcessClose($jocRpt1PID)
    ProcessClose($jocRpt2PID)
    ProcessClose($srpRptPID)
    ProcessClose($reliabilityRptPID)
    ProcessClose($forceUpstreamPID)
    ProcessClose($verifyPID)
    ProcessClose($restorePID)

    ; Re-enable all buttons
    GUICtrlSetState($startScenarioButton, $GUI_ENABLE)
    GUICtrlSetData($startScenarioButton, 'Start Scenario')
    GUICtrlSetState($fileMenuExit, $GUI_ENABLE)
    GUICtrlSetState($crewapi, $GUI_ENABLE)
    GUICtrlSetState($fileMenuAbort, $GUI_DISABLE)
    GUICtrlSetState($testLengthInput, $GUI_ENABLE)
;~  GUICtrlSetState($whereClauseInput, $GUI_ENABLE)
    GUICtrlSetState($crewStatusRateInput, $GUI_ENABLE)
    GUICtrlSetState($etorRateInput, $GUI_ENABLE)
    GUICtrlSetState($dispatcherCommentRateInput, $GUI_ENABLE)
    GUICtrlSetState($crewGPSRateInput, $GUI_ENABLE)
    GUICtrlSetState($referralRateInput, $GUI_ENABLE)
    GUICtrlSetState($outageDetailRateInput, $GUI_ENABLE)
    GUICtrlSetState($troubleRptRateInput, $GUI_ENABLE)
    GUICtrlSetState($amiMeterPingRateInput, $GUI_ENABLE)
    GUICtrlSetState($jocReport1Input, $GUI_ENABLE)
    GUICtrlSetState($jocReport2Input, $GUI_ENABLE)
    GUICtrlSetState($srpReportInput, $GUI_ENABLE)
    GUICtrlSetState($reliabilityReportInput, $GUI_ENABLE)
    GUICtrlSetState($forceUpstreamRateInput, $GUI_ENABLE)
    GUICtrlSetState($verifyRateInput, $GUI_ENABLE)
    GUICtrlSetState($restoreRateInput, $GUI_ENABLE)

    ; Reset flag to indicate that child scripts do not need to be running
    $runningFlag = 0
EndFunc   ;==>runScenario

Func checkChildScripts()
    If $runningFlag = 1 Then
        If $crewStatusRate <> 0 And Not ProcessExists($crewStatusPID) Then
            $crewStatusThroughPut = $crewStatusRate / 3600 ; rate in updates / sec
            ; start crew status update script with specified rate
            ; Send throughput as well as database connection info
            $crewStatusPID = Run(@TempDir & '\performance_scripts\crew_status_updates.exe ' & $crewStatusThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting crew status updates!')
            FileClose($fileHandle)
        EndIf
        If $etorRate <> 0 And Not ProcessExists($etorPID) Then
            $etorThroughPut = $etorRate / 3600 ; rate in updates / sec
            ; start etor update script with specified rate
            ; Send throughput as well as database connection info
            $etorPID = Run(@TempDir & '\performance_scripts\ETOR_Updates.exe ' & $etorThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting ETOR updates!')
            FileClose($fileHandle)
        EndIf
        If $dispatcherCommentRate <> 0 And Not ProcessExists($dispatcherCommentPID) Then
            $dispatcherCommentThroughPut = $dispatcherCommentRate / 3600 ; rate in updates / sec
            ; start crew comment update script with specified rate
            ; Send throughput as well as database connection info
            $dispatcherCommentPID = Run(@TempDir & '\performance_scripts\dispatcher_comments_updates.exe ' & $dispatcherCommentThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting dispatcher comment updates!')
            FileClose($fileHandle)
        EndIf
        If $crewGPSRate <> 0 And Not ProcessExists($crewGPSPID) Then
            $crewGPSThroughPut = $crewGPSRate / 3600 ; rate in updates / sec
            ; start etor update script with specified rate
            ; Send throughput as well as database connection info
            $crewGPSPID = Run(@TempDir & '\performance_scripts\crew_gps_updates.exe ' & $crewGPSThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting crew gps updates!')
            FileClose($fileHandle)
        EndIf
        If $referralRate <> 0 And Not ProcessExists($referralPID) Then
            $referralThroughPut = $referralRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $referralPID = Run(@TempDir & '\performance_scripts\referrals.exe ' & $referralThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting referral creations!')
            FileClose($fileHandle)
        EndIf
        If $outageDetailRate <> 0 And Not ProcessExists($outageDetailPID) Then
            $outageDetailThroughPut = $outageDetailRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $outageDetailPID = Run(@TempDir & '\performance_scripts\outage_detail_callup.exe ' & $outageDetailThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting outage detail callups!')
            FileClose($fileHandle)
        EndIf
        If $troubleRptRate <> 0 And Not ProcessExists($troubleRptDetailPID) Then
            $troubleRptThroughPut = $troubleRptRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $troubleRptDetailPID = Run(@TempDir & '\performance_scripts\trouble_rpt_detail_callup.exe ' & $troubleRptThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting trouble report detail callups!')
            FileClose($fileHandle)
        EndIf
        If $amiMeterPingRate <> 0 And Not ProcessExists($amiMeterPingPID) Then
            $amiMeterPingThroughPut = $amiMeterPingRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $amiMeterPingPID = Run(@TempDir & '\performance_scripts\AMI_Meter_Ping.exe ' & $amiMeterPingThroughPut & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting AMI Meter Ping Requests!')
            FileClose($fileHandle)
        EndIf
        If $jocRpt1Rate <> 0 And Not ProcessExists($jocRpt1PID) Then
            $jocRpt1Throughput = $jocRpt1Rate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $jocRpt1PID = Run(@TempDir & '\performance_scripts\JOC_report_1.exe ' & $jocRpt1Throughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting JOC report 1!')
            FileClose($fileHandle)
        EndIf
        If $jocRpt2Rate <> 0 And Not ProcessExists($jocRpt2PID) Then
            $jocRpt2Throughput = $jocRpt2Rate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $jocRpt2PID = Run(@TempDir & '\performance_scripts\JOC_report_2.exe ' & $jocRpt2Throughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting JOC report 2!')
            FileClose($fileHandle)
        EndIf
        If $srpRptRate <> 0 And Not ProcessExists($srpRptPID) Then
            $srpRptThroughput = $srpRptRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $srpRptPID = Run(@TempDir & '\performance_scripts\srp_report.exe ' & $srpRptThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting srp reports!')
            FileClose($fileHandle)
        EndIf
        If $reliabilityRptRate <> 0 And Not ProcessExists($reliabilityRptPID) Then
            $reliabilityRptThroughput = $reliabilityRptRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $reliabilityRptPID = Run(@TempDir & '\performance_scripts\reliability_report.exe ' & $reliabilityRptThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting reliability reports!')
            FileClose($fileHandle)
        EndIf
        If $forceUpstreamRate <> 0 And Not ProcessExists($forceUpstreamPID) Then
            $forceUpstreamThroughput = $forceUpstreamRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $forceUpstreamPID = Run(@TempDir & '\performance_scripts\force_outage_upstream.exe ' & $forceUpstreamThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting force upstream!')
            FileClose($fileHandle)
        EndIf
        If $verifyRate <> 0 And Not ProcessExists($verifyPID) Then
            $verifyThroughput = $verifyRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $verifyPID = Run(@TempDir & '\performance_scripts\verify_outage.exe ' & $verifyThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting verify!')
            FileClose($fileHandle)
        EndIf
        If $restoreRate <> 0 And Not ProcessExists($restorePID) Then
            $restoreThroughput = $restoreRate / 3600 ; rate in updates / sec
            ; start referral script with specified rate
            ; Send throughput as well as database connection info
            $restorePID = Run(@TempDir & '\performance_scripts\restore_outage.exe ' & $restoreThroughput & ' ' & $astormDBName & ' ' & $astormDBUser & ' ' & $astormDBPass)
            $fileHandle = FileOpen($logFile, 9)
            FileWriteLine($fileHandle, '**ERROR** Restarting restore!')
            FileClose($fileHandle)
        EndIf
    EndIf
EndFunc   ;==>checkChildScripts

Func checkMailslot()
    ; Read from mailSlot and logtoedit if data is found
    While _MailSlotCheckForNextMessage($hMailSlot) <> 0
        $iSize = _MailSlotCheckForNextMessage($hMailSlot)
        $sData = _MailSlotRead($hMailSlot, $iSize, 1)

        logToEdit($loggingEdit, $sData)
        ; Also log to file
        $fileHandle = FileOpen($logFile, 9)
        FileWriteLine($fileHandle, $sData)
        FileClose($fileHandle)
    WEnd

    ; Check for control mailslot messages
    While _MailSlotCheckForNextMessage($cMailSlot) <> 0
        $iSize = _MailSlotCheckForNextMessage($cMailSlot)
        $sData = _MailSlotRead($cMailSlot, $iSize, 1)

        If $sData = 'Start' Then
            WinActivate($loadSimulatorGUI)
            ControlClick('', '', $startScenarioButton)
        ElseIf $sData = 'Stop' Then
            WinActivate($loadSimulatorGUI)
            ControlClick('', '', $fileMenuAbort)
        ElseIf $sData = 'Exit' Then
            _Exit()
        Else
            ConsoleWrite('Received unknown data on mailslot: ' & $sData & @CRLF)
        EndIf
    WEnd
EndFunc   ;==>checkMailslot

Func _Exit()
    ; Delete temp files
    DirRemove(@TempDir & '\performance_scripts\', 1)

    ; Make sure child processes are closed
    ProcessClose($crewStatusPID)
    ProcessClose($etorPID)
    ProcessClose($dispatcherCommentPID)
    ProcessClose($crewGPSPID)
    ProcessClose($referralPID)
    ProcessClose($outageDetailPID)
    ProcessClose($troubleRptDetailPID)
    ProcessClose($amiMeterPingPID)
    ProcessClose($jocRpt1PID)
    ProcessClose($jocRpt2PID)
    ProcessClose($srpRptPID)
    ProcessClose($reliabilityRptPID)
    ProcessClose($forceUpstreamPID)
    ProcessClose($verifyPID)
    ProcessClose($restorePID)

    Exit

EndFunc   ;==>_Exit

Func logToEdit($control, $str)
    _GUICtrlEdit_AppendText($control, $str)
EndFunc   ;==>logToEdit

Func _mySleep($ms)
    $time = TimerInit()
    Sleep($ms - 10)
    Do
        $tmp = TimerDiff($time)
    Until $tmp >= $ms
EndFunc   ;==>_mySleep

; #FUNCTION# ====================================================================================================================
; Name ..........: _ArrayFindAllEx
; Description ...: Similar to _ArrayFindAll with Include, Exclude masks
; Syntax ........: _ArrayFindAllEx(Const Byref $aArray, $sIncludeMask[, $fIncSenstive = True[, $sExcludeMask = ''[,
;                  $fExcSenstive = True]]])
; Parameters ....: $aArray              - [in/out and const] The Array to search for the values.
;                  $sIncludeMask        - A string value.
;                  $fIncSenstive        - [optional] A boolean value. Default is True.
;                  $sExcludeMask        - [optional] A string value. Default is ''.
;                  $fExcSenstive        - [optional] A boolean value. Default is True.
; Return values .: Sucess - Returns the array of the Index of the found values
; - @extended is set to the number of items found
;    Failure  -  Returns '' and sets @error to 1
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......: _ArrayFindAll
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================

Func _ArrayFindAllEx(ByRef Const $aArray, $sIncludeMask, $fIncSenstive = True, $sExcludeMask = '', $fExcSenstive = True)
    ;Set Sensitivity Values
    If $fIncSenstive Then
        $fIncSenstive = ''
    Else
        $fIncSenstive = '(?i)'
    EndIf
    If $fExcSenstive Then
        $fExcSenstive = ''
    Else
        $fExcSenstive = '(?i)'
    EndIf

    ;Make the Include Mask Pattern
    $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)([^\w|])', '[\1]')
    $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)(\[\?\])', '.?')
    $sIncludeMask = StringRegExpReplace($sIncludeMask, '(?s)(\[\+\])', '.+')
    $sIncludeMask = $fIncSenstive & '(?s)(' & StringRegExpReplace($sIncludeMask, '(?s)(\[\*\])', '.*') & ')'

    Local $aRet[1]
    ;Debug Out Include Mask Patterns
    ;ConsoleWrite($sIncludeMask & @CR)

    ;Get the to-include Strings
    For $i = 0 To UBound($aArray) - 1
        If StringRegExp($aArray[$i], $sIncludeMask) Then _ArrayAdd($aRet, $i)
    Next
    _ArrayDelete($aRet, 0)
    If Not IsArray($aRet) Then Return 0
    If Not $sExcludeMask Then Return SetExtended(UBound($aRet), $aRet)

    ;Make the Exclude Mask Pattern
    $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)([^\w|])', '[\1]')
    $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)(\[\?\])', '.?')
    $sExcludeMask = StringRegExpReplace($sExcludeMask, '(?s)(\[\+\])', '.+')
    $sExcludeMask = $fExcSenstive & '(?s)(' & StringRegExpReplace($sExcludeMask, '(?s)(\[\*\])', '.*') & ')'

    ;Debug Out Exclude Mask Patterns
    ;ConsoleWrite($sExcludeMask & @CR)
    Local $nDeleted = 0
    ;Delete the to-exclude strings
    For $i = 0 To UBound($aRet) - 1
        If StringRegExp($aArray[$aRet[$i - $nDeleted]], $sExcludeMask) Then $nDeleted += Number(_ArrayDelete($aRet, $i - $nDeleted) > 0)
    Next
    ;Done
    Return SetError(Not IsArray($aRet), UBound($aRet), $aRet)

EndFunc   ;==>_ArrayFindAllEx

Func MyErrFunc()
;~  MsgBox(0, "AutoItCOM Test - " & @ScriptName, "We intercepted a COM Error !" & @CRLF & @CRLF & _
;~          "err.description is: " & @TAB & $oMyError.description & @CRLF & _
;~          "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
;~          "err.number is: " & @TAB & Hex($oMyError.Number, 8) & @CRLF & _
;~          "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
;~          "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
;~          "err.source is: " & @TAB & $oMyError.source & @CRLF & _
;~          "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
;~          "err.helpcontext is: " & @TAB & $oMyError.helpcontext)
    ConsoleWrite('Encountered an error with ' & @ScriptName & ' Restarting...' & @LF)
EndFunc   ;==>MyErrFunc

Func _WM_COMMAND($hWnd, $msg, $wParam, $1Param)
    If BitAND($wParam, 0x0000FFFF) = $fileMenuAbort Then $fInterrupt = 1
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

HI this is the main script and behind this another scripts invokes so please check the script and give me suggestionss please 

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=bin\Crew_GPS_Updates.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_SaveSource=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <include\_sql.au3>
#include <Array.au3>
#include <Date.au3>
#include <include\MailSlot.au3>
#include <String.au3>

; No tray icon
TraySetState(2)

OnAutoItExitRegister('_Exit')
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Initialize a COM error handler

Global $vehicles, $coords, $numColumns, $numRows, $sql

Global Const $sMailSlotName = "\\.\mailslot\loadprofileupdates"

; Read passed in values
$throughPut = $CmdLine[1]
$astormDBName = $CmdLine[2]
$astormDBUser = $CmdLine[3]
$astormDBPass = $CmdLine[4]
;~ $throughPut = 15
;~ $astormDBName = 'hdshdh'
;~ $astormDBUser = 'ddddd'
;~ $astormDBPass = 'dddddd'

Global $directions[4] = ['North', 'South', 'East', 'West']
Global $travelStatus[4] = ['Travelling', 'Stopped', 'Broken-Down', 'On Break']

Global $count = 0

; Query vehicle table for list of vehicles
$sqlConn = _SQL_Startup()
If _SQL_Connect($sqlConn, $astormDBName, $astormDBUser, $astormDBPass) = $SQL_ERROR Then
    MsgBox(16 + 262144, 'SQL Error', _SQL_GetErrMsg() & @CRLF & $MSSQLObjErr.description)
    Exit
EndIf
If _SQL_GetTable2D(-1, "select vehicle_id, x_coordinate, y_coordinate from vehicle", $vehicles, $numRows, $numColumns) = $SQL_ERROR Then
    MsgBox(16 + 262144, 'SQL Error', _SQL_GetErrMsg())
    _SQL_CLOSE($sqlConn)
    Exit
EndIf
If _SQL_GetTable2D(-1, "Select min (xn_1), max (xn_1), min (yn_1), max (yn_1) from node", $coords, $numRows, $numColumns) = $SQL_ERROR Then
    MsgBox(16 + 262144, 'SQL Error', _SQL_GetErrMsg())
    _SQL_CLOSE($sqlConn)
    Exit
EndIf
_SQL_CLOSE($sqlConn)
; delete column headers
_ArrayDelete($vehicles, 0)

$msg = '***************** Starting GPS Update Scenario *****************' & @CRLF & _
        'Current Time: ' & _NowTime() & @CRLF & 'Througput: ' & Round($throughPut, 4) & ' Crew GPS updates / second' & @CRLF
_MailSlotWrite($sMailSlotName, $msg)

; Object for calling vehicle_api
Dim $cmd = ObjCreate("ADODB.Command")
$cmd.ActiveConnection = 'Provider=OraOLEDB.Oracle.1;Data Source =' & $astormDBName & ';Password=' & $astormDBPass & ';User ID=' & $astormDBUser
$cmd.CommandType = 4
$cmd.CommandText = 'vehicle_api.poll_update_vehicle'
$cmd.Parameters.Append($cmd.CreateParameter('vehicleId', 200, 1, 8, ' '))
$cmd.Parameters.Append($cmd.CreateParameter('xCoord', 3, 1, 10, 0))
$cmd.Parameters.Append($cmd.CreateParameter('yCoord', 3, 1, 10, 0))
$cmd.Parameters.Append($cmd.CreateParameter('velocity', 3, 1, 8, 0))
$cmd.Parameters.Append($cmd.CreateParameter('direction', 200, 1, 20, ' '))
$cmd.Parameters.Append($cmd.CreateParameter('travelStatus', 200, 1, 20, ' '))
$cmd.Parameters.Append($cmd.CreateParameter('ptoStatus', 200, 1, 20, ' '))
$cmd.Parameters.Append($cmd.CreateParameter('errorMsg', 200, 1, 20, ''))
$cmd.Parameters.Append($cmd.CreateParameter('locationTime', 7, 1, 21, 0))
$cmd.Parameters.Append($cmd.CreateParameter('errcode', 3, 2, 0))
$cmd.Parameters.Append($cmd.CreateParameter('errmsg', 200, 2, 256))

; Update outage etor until program is paused/stopped.
While 1
    For $i = 0 To UBound($vehicles) - 1
        $overheadTimer = TimerInit()
        If ($vehicles[$i][1] = 0 Or $vehicles[$i][1] = '') And ($vehicles[$i][2] = 0 Or $vehicles[$i][2] = '') Then
            $xCoord = Random($coords[1][0], $coords[1][1], 1)
            $yCoord = Random($coords[1][2], $coords[1][3], 1)
        Else
            $xCoord = Number($vehicles[$i][1]) + Random(-999999, 999999, 1)
            $yCoord = Number($vehicles[$i][2]) + Random(-999999, 999999, 1)
        EndIf
        $velocity = Random(0, 65, 1)
        $direction = $directions[Random(0, 3, 1)]
        $status = $travelStatus[Random(0, 3, 1)]
        ; Update the command parameters to use a different vehicle each time and randomize coords.
        $cmd.Parameters.Item('vehicleId').value = $vehicles[$i][0]
        $cmd.Parameters.Item('xCoord').value = $xCoord
        $cmd.Parameters.Item('yCoord').value = $yCoord
        $cmd.Parameters.Item('velocity').value = $velocity
        $cmd.Parameters.Item('direction').value = $direction
        $cmd.Parameters.Item('travelStatus').value = $status
;~      ConsoleWrite('vehicleId: ' & $vehicles[$i][0] & ' xCoord: ' & $xCoord & ' yCoord: ' & $yCoord & ' velocity: ' & $velocity & ' direction: ' & $direction & ' status: ' & $status & @LF)
        ; Time has to be in 12hr time, not 24 hr
        If @HOUR > 12 Then
            $hr = @HOUR - 12
            $ampm = 'PM'
        Else
            $hr = @HOUR
            $ampm = 'AM'
        EndIf
        $cmd.Parameters.Item('locationTime').value = @MDAY & '-' & _DateToMonth(@MON, 1) & '-' & StringRight(@YEAR, 2) & ' ' & $hr & ':' & @MIN & ':' & @SEC & ' ' & $ampm

        $cmd.Execute

        ; Check error codes to verify if the operation was successful
        $errCode = $cmd.Parameters('errcode').Value
        $errMsg = $cmd.Parameters('errmsg').Value

;~      ConsoleWrite('error code: ' & $errCode & ' errmsg: ' & $errMsg & @LF)

        If $errCode <> 0 Then
            Switch $errCode
                Case 1
                    $msg = 'Vehicle: ' & $vehicles[$i][1] & ' does not exist!' & @CRLF
                    _MailSlotWrite($sMailSlotName, $msg)
                Case 2
                    $msg = 'Vehicle: ' & $vehicles[$i][1] & ' is not AVL equipped!' & @CRLF
                    _MailSlotWrite($sMailSlotName, $msg)
                Case 3
                    $msg = 'Vehicle: ' & $vehicles[$i][1] & ' has no current ping requests!' & @CRLF
                    _MailSlotWrite($sMailSlotName, $msg)
            EndSwitch
        EndIf

        ; Increase count and if multiple of 100, send message back to monitor app
        $count += 1
        If IsInt($count / 100) Then
            $msg = _NowTime() & ' | GPS Update Scenario | ' & $count & @CRLF
            _MailSlotWrite($sMailSlotName, $msg)
        EndIf

        $overheadTime = TimerDiff($overheadTimer)
        _mySleep((1000 / $throughPut) - $overheadTime)
    Next
WEnd

Func _Exit()
    ; Close sql connection
    _SQL_CLOSE($sqlConn)
EndFunc   ;==>_Exit

Func _mySleep($ms)
    $time = TimerInit()
    Sleep($ms - 10)
    Do
        $tmp = TimerDiff($time)
    Until $tmp >= $ms
EndFunc   ;==>_mySleep

Func MyErrFunc($oMyError)
;~  MsgBox(0, "AutoItCOM Test - " & @ScriptName, "We intercepted a COM Error !" & @CRLF & @CRLF & _
;~          "err.description is: " & @TAB & $oMyError.description & @CRLF & _
;~          "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
;~          "err.number is: " & @TAB & Hex($oMyError.Number, 8) & @CRLF & _
;~          "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
;~          "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
;~          "err.source is: " & @TAB & $oMyError.source & @CRLF & _
;~          "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
;~          "err.helpcontext is: " & @TAB & $oMyError.helpcontext & @CRLF & _
;~          "err.sqltext is: " & @TAB & $sql)
    $msg = _NowTime() & ' | GPS Update Scenario | ' & "AutoItCOM Test - " & @ScriptName & "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.Number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext & @CRLF & _
            "err.sqltext is: " & @TAB & $sql
    _MailSlotWrite($sMailSlotName, $msg)
EndFunc   ;==>MyErrFunc

This is the sub script i got connection error and subscripts errror please help on this

Link to comment
Share on other sites

Thank you for posting some example code.

It is not jumping out at my why the _SQL_CLOSE error would be occurring, but the message is saying the variable $sqlConn isn't declared before it is being sent to the the _SQL_CLOSE function. 

For the $CmdLine error, sounds like no command line parameters are being sent to the script/exe. If your script relies on command line parameters to work, and none are provided, you should probably add some error checking.  For example:

;if your script is expecting four cmd line paramters to work, verify that four params were provided before executing the script
If $CmdLine[0] <> 4 Then Exit

;Also a good idea to add additional error checking that the 4 parameters are expected values

Regarding getting help with the _sql.au3 and MailSlot.au3 UDFs, the authors, if they are still active members on the forums, would be the best contacts.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...