‘Dts’ 这个名称在当前上下文中不存在。

huangapple go评论67阅读模式
英文:

The name 'Dts' does not exist in its current context

问题

I'm trying to run a send email Script task in SSIS because I need it in the Data flow task.

I'm getting

The name 'Dts' does not exist in its current context

error

Is there a missing namespace?

‘Dts’ 这个名称在当前上下文中不存在。

‘Dts’ 这个名称在当前上下文中不存在。

英文:

I'm trying to run a send email Script task in SSIS because I need it in the Data flow task.

I'm getting

> The name 'Dts' does not exist in its current context

error

Is there a missing namespace?

‘Dts’ 这个名称在当前上下文中不存在。

‘Dts’ 这个名称在当前上下文中不存在。

答案1

得分: 0

以下是翻译好的部分:

有两种名为Script的东西在SSIS中。

Script Task是在SSIS包的控制流部分发生的顶级活动。这是“在.NET中做任何SSIS没有内置的事情”的瑞士军刀。

Script Component是在数据流任务的上下文中发生的特定于数据流的活动。它们可以在每一行的基础上操作,可以是源、接收器或仅仅是数据行的修改器。

正如Yitzhak所观察到的,看起来您正在使用错误的那一个。

要访问Script Task中的变量,假设您已经勾选了将它们添加到脚本中的复选框,您可以像您所示的那样访问它们。即 string htmlMessageFrom = Dts.Variables["EmailFrom"].Value.ToString();

要访问Script Component中的变量,那是不同的方法。您仍然需要指示组件可用的变量,但在访问它时不需要将数据强制转换为适当的类型,因为在访问时它将是强类型的。例如 string htmlMessageFrom = this.Variables.EmailFrom;

英文:

There are two Script named things in SSIS.

A Script Task is a top level activity that occurs in the Control Flow section of an SSIS package. This is the "do anything in .NET that we didn't build into SSIS" swiss army knife.

A Script Component is a Data Flow specific activity that occurs within the context of a Data Flow Task. These can operate on a per-row basis, be the source, sink or just a modifier of data rows.

As Yitzhak observes, it appears you are using the wrong one.

To access variables in a Script Task, assuming you've checked the box to add them into the Script, you would access them as you have shown. i.e. string htmlMessageFrom = Dts.Variables["EmailFrom"].Value.ToString();

To access variables in a Script Component, that's a different route. You'd still need to indicate which variables are available to the component but there is no need to cast the data to the appropriate type as it will be strongly typed as you access it. e.g. string htmlMessageFrom = this.Variables.EmailFrom;

huangapple
  • 本文由 发表于 2023年6月6日 02:15:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定