VBS DTEXEC - SSIS Package fails to fully execute before continuing on

172 Views Asked by At

I have a vbs script that's failing to finish loading a file before moving on to the next steps. I've been using this code for 2+ years so this is likely due to my poor code and error handling - If the SSIS package fails to fully load, the procedure should kick out and alert me - Can someone point me in the right direction to make sure this package fully loads or if it fails, truncate the stage table and try again?

The file can range from 50mb to 1.2Gb

'******************************
Sub ReloadTable(strTableName)
'******************************
    Dim wsh 
    Set wsh = CreateObject("WScript.Shell")

    Dim waitOnReturn 
    waitOnReturn = True

    Dim windowStyle
    windowStyle = 0

    Dim errorCode
    Dim DTEXECStatus


    'Truncate the stage table
    ExecOnSQL "TRUNCATE TABLE essstage." & strTableName

    'Run the SSIS package and wait until complete
        errorCode = wsh.Run("dtexec /File ""\\server.dev.local\Data\SSIS SQL16\" & strTableName & ".dtsx"" ", windowStyle, waitOnReturn)
        If errorCode = 0 Then
            DTEXECStatus = "Success! " & strTableName
            'MsgBox "Success! " & strTableName
        Else
            'Should exit the sub if this fails and notify me
            DTEXECStatus = "FAILED!! " & strTableName
            Create_NOTICE_Email
            MsgBox "Failed! " & strTableName
            'It'd be better if this repeated the steps to clear/attempt to reload again but who knows how to do that 
            Exit Sub
            'ML: Added this END to the script to see if it'll stop erroring out
        End If

End Sub

'******************************
Sub ExecOnSQL(cmdTxt)
'******************************
        Dim strConnSQL
        strConnSQL = "Provider=SQLOLEDB; Server=SQLSERVER.dev.LOCAL; Database=goldmouse; Trusted_Connection=Yes"

    'Open the connection to the database
        Dim cn
        Set cn = CreateObject("ADODB.Connection")
        cn.Open strConnSQL

    'Set the command
        Dim cmd
        Set cmd = CreateObject("ADODB.Command")
        Set cmd.ActiveConnection = cn

    'Set the record Set
        Dim rs
        Set rs = CreateObject("ADODB.recordSet")

    'Prepare the command
        cmd.CommandText = cmdTxt
        cmd.CommandType = 1  'adCmdText
        cmd.CommandTimeout = 3000   '50 minutes
        'cmd.CommandType = 4  'adCmdStoredProc


    'Execute the command
        Set rs = cmd.Execute
        Set cmd = Nothing

    'Close connections
        cn.Close
        Set cn = Nothing

End Sub

0

There are 0 best solutions below