简体   繁体   English

从C#asp启动器读取SSIS包变量

[英]reading a SSIS package variable from it's C# asp launcher

I have to modify an existing SSIS package, to launch it from a web site. 我必须修改现有的SSIS程序包,才能从网站启动它。 Currently, this package is launched on demand by double clicking it, shows a form to ask for an excel file location and some database credentials that are stored in package variables, and then loads data from the excel file into a DB. 当前,通过按需双击该程序包将其启动,显示一个表格以询问excel文件位置和存储在程序包变量中的某些数据库凭据,然后将数据从excel文件加载到数据库中。 Since there are many errors that can occur in the process, there is a package variable that holds an internal state, to inform the user which part of the process failed. 由于过程中可能发生许多错误,因此有一个包变量保存内部状态,以通知用户过程的哪一部分失败。

Given that I have to launch the package from a web site, as a first approach I have split the package in two, a master package that gets the information from user, executes the slave package by passing the user parameters through package variables, gets the child package internal state and then it finishes by informing the user the final state of this process. 鉴于我必须从网站启动程序包,作为第一种方法,我将程序包一分为二,一个主程序包从用户那里获取信息,通过将用户参数传递给程序包变量来执行从属程序包,子包内部状态,然后通过通知用户此过程的最终状态来完成。 The communication between packages is being done by using variables with the same name and package configuration (main package variables). 软件包之间的通信是通过使用具有相同名称和软件包配置的变量(主要软件包变量)来完成的。 This is true for all variables except for the internal state one, that exists just in the parent, but is used in the child. 对于除了内部状态1之外的所有变量,这都是正确的,内部状态1仅存在于父级中,而在子级中使用。 Since both share the same context, it works ok. 由于两者共享相同的上下文,因此可以正常工作。

Now that the child package is isolated, I'm trying to replace the master one with a C# asp site. 现在,子程序包已被隔离,我正在尝试用C#asp站点替换主程序包。 Currently I'm able to get the user parameters through a webform and execute the package, but I can't figure how to read the child's internal state variable from the web app. 目前,我可以通过Web表单获取用户参数并执行程序包,但无法确定如何从Web应用程序读取孩子的内部状态变量。

This internal value is an integer from 0 to 12, where 0 means ok and any other means that something went wrong with loading a table, executing a SP or something else. 此内部值是0到12之间的整数,其中0表示可以,其他表示装入表,执行SP或其他操作时出错。

There is a way to get this package variable value from the web app, when the package finishes? 有什么办法可以从Web应用程序中获取包变量值,包何时完成? Otherwise, I just realized that this could be wrote in a log file that could be read by the web app, but I was wondering if there is a more wise solution. 否则,我只是意识到可以将其写在Web应用程序可以读取的日志文件中,但是我想知道是否有更明智的解决方案。


Just to let you know, this is how I'm passing variables from the web app to the package. 只是让您知道,这就是我将变量从Web应用程序传递到程序包的方式。 The package is configured to set its variables from primary/main package variables. 程序包配置为从主要/主要程序包变量设置其变量。

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SqlServer.Dts.Runtime;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Application app = new Application();
        Package package = null;
        String PackagePath = "";
        try
        {  

            string fileName = FileUpload1.PostedFile.FileName.ToString();
            fileName = Server.MapPath("App_Data//" + System.IO.Path.GetFileName(fileName));
            FileUpload1.PostedFile.SaveAs(fileName);            

            //Load DTSX    
            PackagePath = @"C:\Program Files\Microsoft SQL Server\100\DTS\Packages\Null Project\Package.dtsx";
            package = app.LoadPackage(PackagePath, null);            

            //Global package variables (same name)
            Hashtable param = new Hashtable();
            param["ServidorOrigen"] = "SQL_SERVER";
            param["UserOrigen"] = "user";
            param["PassOrigen"] = "pass";
            param["BaseDatosOrigen"] = "test_database";
            param["EstadoConexion"] = 0;
            param["EstadoPaquete"] = 0;
            param["ExcelRuta"] = fileName.ToString();

            Variables vars = null;

            foreach (DictionaryEntry entry in param)
            {
                package.VariableDispenser.LockOneForWrite(entry.Key.ToString(), ref vars);

                try
                {
                    vars[entry.Key.ToString()].Value = entry.Value.ToString();
                }
                catch
                {
                    throw new Exception("variable " + entry.Key.ToString() + " not found in package");
                }
                finally
                {
                    vars.Unlock();
                }
            }

            //Execute DTSX
            Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();

            //Collects debugging info
            using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/App_Data/log.txt"), true))
            {
                if (!package.Errors.Count.Equals(0)){
                    _testData.WriteLine(package.Errors.Count.ToString()); // Write the file.

                    ErrorEnumerator myEnumerator = package.Errors.GetEnumerator();
                    int i = 0;
                    while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))
                        _testData.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Description);
                }
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
}

You can store the state in a database table the same way you would with your log file and then just have your web app read that at a given interval. 您可以像使用日志文件一样将状态存储在数据库表中,然后让Web应用程序以给定的间隔读取状态。

I'm not sure how you are passing your variables from the web app to the ssis, but you could look into the ssis configuration stuff storing in sql databases. 我不确定如何将变量从Web应用程序传递到ssis,但是您可以研究存储在sql数据库中的ssis配置内容。

I have a similar thing I do. 我也有类似的事情。

  1. Config stuff saved to database from web app. 配置从Web应用程序保存到数据库的内容。
  2. Web app calls a sql job. Web应用程序调用一个sql作业。
  3. Job starts ssis package. 作业启动sis软件包。
  4. Web app queries every minute to see if the job has finished and returns succeeded or failed to user. Web应用程序每分钟查询一次,以查看作业是否已完成,并向用户返回成功还是失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM