SSIS 脚本组件无法写入 ReadWriteVariable
我在 SQLServer 2008 R2 上的 SSIS 中有一个脚本组件,它需要能够写入读写变量以生成用于平面文件导出的文件名。我创建了一个包级变量来保存文件名,并将平面文件连接设置为使用包含该变量的表达式。
我有一个脚本组件,除其他外,它在执行后方法中动态构建文件名。我已在脚本组件的 ReadWriteVariables 设置中设置了该变量。
如果变量中没有默认值,包将立即失败,因为平面文件连接管理器尝试评估表达式以设置目标文件。所以,我只是输入了一个占位符文件名。
问题是现在它总是使用占位符文件名而不是脚本指定的文件名。确保我可以写入这些变量的最佳方法是什么?我尝试了 Variables.VariableName = "value",我还尝试使用 VariableDispenser 和 this.ReadWriteVariables["VariableName"].value,但它们都没有保留我在脚本中设置的值。
I have a script component in SSIS on SQLServer 2008 R2, that needs to be able to write to a Read-Write variable to produce a file name for a flat file export. I created a package level variable to hold the file name, and set the flat file connection to use an expression containing the variable..
I have a script component that, among other things, builds the file name dynamically in the post execute method. I've set the variable in the ReadWriteVariables setting of the script component.
The package will immediately fail if I don't have a default value in the variable, because the flat file connection manager tries to evaluate the expression to set up the destination file. So, I just put in a placeholder file name.
The problem is that now it always uses the placeholder filename instead of the one that the script specifies. What's the best way to make sure that I can write to those variables? I tried Variables.VariableName = "value", I've also tried using VariableDispenser and this.ReadWriteVariables["VariableName"].value, and none of them are persisting the value I set in the script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种从
数据流任务
内可用的脚本组件
为包变量赋值的方法。我尝试锁定脚本任务或脚本组件内的变量,而不是在“属性”对话框中指定它们。我觉得这样更容易维护。
在下面的示例中,我有一个名为 FileName 的包变量,并且在脚本组件C:\Temp\PathChanged嗯>。
我相信脚本组件可能不是操作包变量值(例如文件名)的正确位置,但这又取决于您想要执行的操作。
希望有帮助。
Here is one way you can assign value to a package variable from within
Script Component
available insideData Flow Task
.I try to lock the variables inside the
Script Task
orScript Component
instead of specifying them on Properties dialog. I feel this is easier to maintain.In the following example, I have a package variable named FileName and the variable is being assigned with the value
C:\Temp\PathChanged
inside the Script Component.I believe that Script Component may not be the right place to manipulate the package variable value such as file name but again that depends on what you are trying to do.
Hope that helps.