SSIS读取操作系统环境变量

时间:2020-05-24 14:54:51

标签: ssis script-task

在Windows系统上,当我打开DOS命令窗口时,可以通过运行以下命令来检索操作系统环境变量的值:

C:\ Users \ me>设置MyApplicationEnvironment MyApplicationEnvironment =登台

我想在SSIS环境中做同样的事情。有没有人对最佳方法有任何想法?

谢谢!

1 个答案:

答案 0 :(得分:1)

创建类型为字符串MyApplicationEnvrionment的SSIS变量

添加脚本任务并指定@ [User :: MyApplicationEnvironment]是读/写变量。

假设使用C#,Main的内容将类似于

var env = System.Environment.GetEnvironmentVariable("MyApplicationEnvironment");
if (env != null)
{
    Dts.Variables["User::MyApplicationEnvironment"].Value = env;
}
// TODO: what should happen if the variable is not found

Environment.GetEnvironmentVariable

我们将其分配给我们要更新的Dts变量的.Value属性。