簡體   English   中英

如何將變量從C#應用程序傳遞到SSIS包

[英]How to pass variables to an SSIS package from a C# application

基本上,我試圖構建一個使用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);
    }

有人知道如何以這種方式將變量傳遞給包嗎?

您需要使用Package.Variables屬性。

        Package package = null;
        package = app.LoadPackage(@"C:\ft\Package.dtsx", null);
        package.Variables["User::varParam"].Value = "param value";

試試看:

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM