我想从C#代码执行位于服务器上的SSIS包。
我正试图让这个运行:
public void Execute()
{
string folderName = "MYFOLDER";
string projectName = "MYPROJECT";
string serverName = @"MYSERVER\REGION";
String connectionString = String.Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", serverName);
using(SqlConnection sqlConnection = new SqlConnection(connectionString)) {
IntegrationServices integrationServices = new IntegrationServices(sqlConnection);
Catalog catalog = integrationServices.Catalogs["SSISDB"];
CatalogFolder catalogFolder = catalog.Folders[folderName];
PackageInfo package = catalogFolder.Projects[projectName].Packages[PackageName];
PackageInfo.ExecutionValueParameterSet batchIdParameter = new PackageInfo.ExecutionValueParameterSet {
ObjectType = package.Parameters["BatchId"].ObjectType,
ParameterName = "BatchId",
ParameterValue = package.Parameters["BatchId"].DesignDefaultValue
};
PackageInfo.ExecutionValueParameterSet dateIdParameter = new PackageInfo.ExecutionValueParameterSet
{
ObjectType = package.Parameters["DateId"].ObjectType,
ParameterName = "DateId",
ParameterValue = package.Parameters["DateId"].DesignDefaultValue
};
Collection<PackageInfo.ExecutionValueParameterSet> setValueParameters = new Collection<PackageInfo.ExecutionValueParameterSet>();
setValueParameters.Add(batchIdParameter);
setValueParameters.Add(dateIdParameter);
long executionId = package.Execute(false, null, setValueParameters);
}
}
当我运行此代码时,出现错误:System.Data.SqlClient.SqlException: In order to execute this package, you need to specify values for the required parameters.
(两个参数都有DesignDefaultValue)
但是当我通过MS SQL Server Management Studio查看软件包时,我只在参数页面&gt;参数选项卡下看到两个参数BatchId
和DateId
作为必需参数。
为什么程序包不会运行?
答案 0 :(得分:5)
找到它:您还必须设置对环境的引用并将其提供给PackageInfo.Execute
方法,而不是使用null
:
EnvironmentReference environmentReference = catalogFolder.Projects[projectName].References["ProjectName", "."];
long executionId = package.Execute(false, environmentReference, setValueParameters);