基本上我正在尝试构建一个使用SSIS来运行一系列sql的应用程序。
到目前为止,这是我的代码:
public JsonResult FireSSIS()
{
string x = string.Empty;
try
{
Application app = new Application();
Package package = null;
package = app.LoadPackage(@"C:\ft\Package.dtsx", null);
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();
if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
{
foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
{
x += string.Concat("Package Execution results: {0}", local_DtsError.Description.ToString());
}
}
}
catch (DtsException ex)
{
// Exception = ex.Message;
}
return Json(x, JsonRequestBehavior.AllowGet);
}
有人知道如何以这种方式将变量传递给包本身吗?
答案 0 :(得分:11)
您需要使用Package.Variables
属性。
Package package = null;
package = app.LoadPackage(@"C:\ft\Package.dtsx", null);
package.Variables["User::varParam"].Value = "param value";
答案 1 :(得分:10)
试试:
Microsoft.SqlServer.Dts.RunTime.Variables myVars = package.Variables; myVars["MyVariable1"].Value = "value1"; myVars["MyVariable2"].Value = "value2"; Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute(null, myVars, null, null, null);