Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SSIS中使用脚本任务传递变量_Ssis - Fatal编程技术网

在SSIS中使用脚本任务传递变量

在SSIS中使用脚本任务传递变量,ssis,Ssis,我在ssis包中有一个C#脚本,如下所述 SqlConnection importTab = new SqlConnection(@"Server=ServerName; Integrated Security=true;user=;pwd=;database=DBname"); 我需要在变量中传递数据库名(DBName) 可能是这样 SqlConnection importTab = new SqlConnection(@"Server=ServerName; Integrated

我在ssis包中有一个C#脚本,如下所述

SqlConnection importTab = new SqlConnection(@"Server=ServerName;  
Integrated Security=true;user=;pwd=;database=DBname");
我需要在变量中传递数据库名(DBName)

可能是这样

SqlConnection importTab = new SqlConnection(@"Server=ServerName;  
Integrated Security=true;user=;pwd=;database="+"User::Variable" +");"
Dts.Variables["User::Variable"].Value.ToString()

但是我知道我错了…

脚本任务中的以下代码可能会对您有所帮助

var dbServerName = Dts.Variables["yourVariableName"].Value.ToString();

var sqlConnString = string.Format("Server=ServerName;Integrated Security=true;user=;pwd=;database={0}", dbServerName);

SqlConnection sqlConn = new SqlConnection(sqlConnString);

脚本任务中的以下代码可能会对您有所帮助

var dbServerName = Dts.Variables["yourVariableName"].Value.ToString();

var sqlConnString = string.Format("Server=ServerName;Integrated Security=true;user=;pwd=;database={0}", dbServerName);

SqlConnection sqlConn = new SqlConnection(sqlConnString);
我是这样做的:

打开脚本任务属性时,有两个字段,
ReadOnlyVariables
ReadWriteVariables
。在您的情况下,根据您的需要将变量名写入相应的字段
User::variable

在代码中,您可以这样使用它

SqlConnection importTab = new SqlConnection(@"Server=ServerName;  
Integrated Security=true;user=;pwd=;database="+"User::Variable" +");"
Dts.Variables["User::Variable"].Value.ToString()
我是这样做的:

打开脚本任务属性时,有两个字段,
ReadOnlyVariables
ReadWriteVariables
。在您的情况下,根据您的需要将变量名写入相应的字段
User::variable

在代码中,您可以这样使用它

SqlConnection importTab = new SqlConnection(@"Server=ServerName;  
Integrated Security=true;user=;pwd=;database="+"User::Variable" +");"
Dts.Variables["User::Variable"].Value.ToString()

要在脚本中使用变量,首先确保已将该变量添加到脚本中 ReadOnlyVariables属性中包含的列表或 此脚本任务的ReadWriteVariables属性,取决于 代码需要写入变量

//Example of reading from a variable:
DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;

//Example of writing to a variable:
Dts.Variables["User::myStringVariable"].Value = "new value";

//Example of reading from a package parameter:
int batchId = (int) Dts.Variables["$Package::batchId"].Value;

//Example of reading from a project parameter:
int batchId = (int) Dts.Variables["$Project::batchId"].Value;

//Example of reading from a sensitive project parameter:
int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();

要在脚本中使用变量,首先确保已将该变量添加到脚本中 ReadOnlyVariables属性中包含的列表或 此脚本任务的ReadWriteVariables属性,取决于 代码需要写入变量

//Example of reading from a variable:
DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;

//Example of writing to a variable:
Dts.Variables["User::myStringVariable"].Value = "new value";

//Example of reading from a package parameter:
int batchId = (int) Dts.Variables["$Package::batchId"].Value;

//Example of reading from a project parameter:
int batchId = (int) Dts.Variables["$Project::batchId"].Value;

//Example of reading from a sensitive project parameter:
int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();

连接字符串中不应同时包含
Integrated Security=true
和用户ID及密码,请选择其中一个。使用连接字符串中不应同时包含
Integrated Security=true
和用户ID及密码,请选择其中一个。使用