使用带参数的包,首先引入
using Microsoft.SqlServer.Dts.Runtime;
然后在程序中为包变量赋值,具体方法代码:
private void runetl()
{
Console.WriteLine("ETL start...");
string filepath = installedPath + "\\etl\\Package.dtsx";
Microsoft.SqlServer.Dts.Runtime.Application application = new Microsoft.SqlServer.Dts.Runtime.Application();
Package package = application.LoadPackage(filepath, null, true);
package.Variables["dbservername"].Value = dwservername;
package.Variables["dbname"].Value = dwdbname;
package.Variables["varFolderName"].Value = thispath;
DTSExecResult result = package.Execute();
if (result.Equals(DTSExecResult.Success))
listBox1.Items.Add("ETL success");
else
{
listBox1.Items.Add("ETL failed");
return;
}
}