微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQL作业中发生错误,调用的目标已引发异常

如何解决SQL作业中发生错误,调用的目标已引发异常

我在SSIS项目中遇到了大问题。

当我在SSIS本地计算机中执行项目时,dtsx运行良好,但是当我将其放入sql Agent Job中时,会抛出错误

来源:文件夹中的文件?说明:调用的目标已引发异常。结束错误错误:2020-10-02 17:37:05.33代码:0x00000001源:脚本任务1说明:调用目标已引发异常。结束错误DTExec:程序包执行返回DTSER_FAILURE(1)。开始:17:37:01完成:17:37:05经过:3.687秒。程序包执行失败。步骤失败。

文件夹中的源文件”是一个脚本任务,具有以下代码

    Dim StrFolderArrary As String()
    Dim StrFileArray As String()
    Dim fileName As String
    Dim RemoteDirectory As String

    RemoteDirectory = Dts.Variables("User::ftp_masks").Value.ToString()

    Dim cm As ConnectionManager = Dts.Connections("FTP Connection Manager") 'FTP connection manager name
    Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(nothing))

    Try
        ftp.Connect() 'Connecting to FTP Server

        ftp.SetWorkingDirectory(RemoteDirectory) 'Provide the Directory on which you are working on FTP Server

        ftp.GetListing(StrFolderArrary,StrFileArray) 'Get all the files and Folders List

        'If there is no file in the folder,strFile Arry will contain nothing,so close the connection.

        If StrFileArray Is nothing Then

            MessageBox.Show(Dts.Variables("User::FileExistsFlg").Value.ToString())

            Dts.Variables("User::FileExistsFlg").Value = 0

            ftp.Close()


            'If Files are there,Loop through the StrFileArray arrary and insert into table
        Else

            For Each fileName In StrFileArray

                MessageBox.Show(fileName)
                Dts.Variables("User::files").Value = fileName
                MessageBox.Show(Dts.Variables("User::files").Value.ToString())
                If fileName = Dts.Variables("User::files").Value.ToString() Then
                    Dts.Variables("User::FileExistsFlg").Value = 1
                    MessageBox.Show(Dts.Variables("User::FileExistsFlg").Value.ToString())
                End If
            Next
            Dts.TaskResult = ScriptResults.Success

            ftp.Close()

        End If

        MessageBox.Show("End try")

    Catch ex As Exception

        MessageBox.Show("Catch")
        Dts.Events.FireError(0,"My File Task",ex.Message,String.Empty,0)
        MessageBox.Show("Stack Trace: " & vbCrLf & ex.StackTrace)
        Throw New ApplicationException("Something happened :(",ex)
        'Dts.TaskResult = ScriptResults.Failure
    Finally
        ' This line executes whether or not the exception occurs.
        MessageBox.Show("in Finally block")

    End Try

    '
    ' Add your code here
    '
    Dts.TaskResult = ScriptResults.Success

有人可以帮助我吗? 如何查看具体错误

谢谢您的时间。

解决方法

代码的挑战之一是使用MessageBox。这是一个交互式UI元素。当SSIS包以无人参与模式运行时,您将无法使用这些文件,因为服务器上会弹出一个窗口,阻止所有进度,直到有人登录并单击“确定”。是的,那完全发生在DTS时代(2005年之前)。

保留弹出窗口的一种方法是测试InteractiveMode的系统范围变量。您需要在ReadOnly变量列表中进行检查,然后将代码修改为

VB近似

' This is not valid VB syntax but I can't remember their declaration/initialization sytnax
Dim interactiveMode as Boolean =  (bool) Dts.Variables["System::InteractiveMode"].Value

if interactiveMode then
    MessageBox.Show(fileName)
End If

raise Information messages更好的方法。这些工作都参加了无人值守模式。

这是C#,欢迎您转换为VB语法

bool fireAgain = false;
string message = "{0}:{1}";

Dts.Events.FireInformation(0,"SCR Echo Back",string.Format(message,"RemoteDirectory",RemoteDirectory),string.Empty,ref fireAgain);

Dts.Events.FireInformation(0,"fileName",fileName),ref fireAgain);

那将转储到信息日志中的远程目录和fileName值。在VS中,这将显示在“输出”窗口以及“包执行结果”图形窗口中。在服务器上,该文件将转储到SSISDB.catalog.OperationMessages

所有这些都说明了,还有什么可能发生?

  • 我似乎还记得,如果文件夹为空,则ftp客户端将引发异常。
  • 服务器可能具有防火墙/防病毒功能,阻止对端口22/23的出站访问 (ftp)。
  • 您的连接管理器实例化可能会引发异常
  • 与ftp客户端连接相同。
  • 如果这不是匿名访问,则可能是服务器版本的代码未获得凭据信息,因为它在部署时从基本软件包中删除了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。