1

我有一个 vbs 脚本在继续下一步之前未能完成加载文件。我已经使用此代码 2 年多,所以这可能是由于我的代码和错误处理不佳 - 如果 SSIS 包无法完全加载,该过程应该退出并提醒我 - 有人能指出我正确的方向吗要确保这个包完全加载,或者如果它失败,截断舞台表并重试?

该文件的范围可以从 50mb 到 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

4

0 回答 0