【问题标题】:SSIS - How to use results of Execute SQL Task to call a Web ServiceSSIS - 如何使用执行 SQL 任务的结果来调用 Web 服务
【发布时间】:2019-12-10 13:42:51
【问题描述】:

我需要使用来自 SQL SELECT 的结果,它应该返回一个 ID 数组,以便在我的 foreach 循环中遍历它。 我对SSIS很陌生。我创建了执行 SQL 任务,连接到数据库并写入

SELECT ID FROM TABLE

然后我创建了 Script Task 并将这两个组件与 Constraint 连接起来。但我不知道如何将 SQL 任务的结果传递给脚本任务中的对象。

【问题讨论】:

    标签: ssis script-task execute-sql-task


    【解决方案1】:

    您正在寻找的典型模式是这样的:

    1. In execute SQL you need to:
    a. Assign the connection
    b. Add your SQL Statement
    c. Change Result Set to Full Result Set
    d. Map the result set to an Object type variable
    
    2. In Foreach
    a. Change enumerator to ADO Enum
    b. Assign your variable from #1
    c. Map a variable to the interation
    

    ****EDIT****
    3. Change out data flow for script task
    a. Pass in iteration variable
    b. in script create the URL as a string
    c. use webclient to connect to web service
    
    
    string url = @"https://www.blah.com? ID=" + 
                 Dts.Variable["variable"].Value.ToString();
    
    WebClient wc = new WebClient();
    string result = wc.DownloadString(url);
    
    4. Now you have to do something with that result
    

    【讨论】:

    • 如果你真的想跳到一个脚本任务中,那么你需要把第 1 步中的对象变量带入一个脚本任务中,并将它加载到一个数据表中。但如果你这样做,我宁愿直接用脚本任务中的 SQL 加载数据表。
    • 非常感谢@KeithL,我需要为源表中的每个 ID 调用 REST API,并且 ID 是被调用 URL 的一部分,因此我需要以某种方式将 ID 获取到脚本任务中跨度>
    • 好好利用这个和脚本任务。更改脚本任务的数据流。我将更新第 3 步
    • 再次感谢您。你是野兽。但我不确定是否传入迭代变量...所以我在 foreach 循环中的 Collection 中放入 ADO 对象源变量的同一个变量我应该在 Script Task 的 Script 中放入 ReadOnlyVariables?
    • 2c。将变量映射到 Foreach 侧的迭代。我会添加一张图片。
    猜你喜欢
    • 1970-01-01
    • 2010-10-26
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多