SSIS: Use System::TaskName inside the dataflow

纵饮孤独 提交于 2019-12-20 04:52:03

问题


For more detailed logging, I want to retrieve the [System::TaskName]

Right now, when starting from the task that fails we go to 'script task', there I fetch [System::TaskName] and write that in the log. Logically this writes the current TaskName = 'Script task' instead of the failed task

Problem is the System::TaskName is only know inside the task, logical... In fact I want to update a variable 'User::CurrentTaskName' from inside the dataflow, = from inside the task.

This would be easiest if I could use a 'Script Task' component inside a dataflow but I can't find that. Probably I need a workaround.

Hope you guys understand approximately what I mean...

Thanks in advance!


回答1:


I was able to access the TaskName by adding the following inside a Script Component.

Private Function ReadVariable(ByVal varName As String) As Object
    Dim result As Object
    Try
        Dim vars As IDTSVariables100
        Me.VariableDispenser.LockForRead(varName)
        Me.VariableDispenser.GetVariables(vars)
        Try
            result = vars(varName).Value
        Catch ex As Exception
            Throw ex
        Finally
            vars.Unlock()
        End Try
    Catch ex As Exception
        Throw ex
    End Try
    Return result
End Function

and then accessing the variable like so

ReadVariable("System::TaskName")



回答2:


From the looks of your data flow, it looks like you're trying to implement error logging. I've had good luck using an event handler for this sort of thing in the past. It has the added benefit of cleaning up your layout and making the maintenance of the package easier in the future as you don't need to maintain linkage from all of your tasks to the error handling.



来源:https://stackoverflow.com/questions/8123544/ssis-use-systemtaskname-inside-the-dataflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!