【问题标题】:SSIS Web Service Script Component (The given key was not present in the dictionary)SSIS Web 服务脚本组件(字典中不存在给定的键)
【发布时间】:2017-08-15 01:48:04
【问题描述】:

如果这个问题已经得到解答,我很抱歉,但我已经做了一些研究,还没有找到有意义的东西。

我正在创建一个连接到 Web 服务并将数据转储到 SQL 表中的 SSIS 脚本组件。尽管脚本组件仍在进行中,但我目前收到以下错误: 在 System.Collections.Generic.Dictionary`2.get_Item(TKey 键) 在 ScriptMain.CreateNewOutputRows() 在 UserComponent.PrimeOutput(Int32 输出,Int32[] OutputIDs,PipelineBuffer[] 缓冲区,OutputNameMap OutputMap) 在 Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PrimeOutput(Int32 输出,Int32[] outputIDs,PipelineBuffer[] 缓冲区)

这是我用于脚本组件的核心代码:

  public Dictionary<string, int> agentStatisticsColumns = new Dictionary<string, int>();

public override void CreateNewOutputRows()
{

    //setSessionParameters sessionParams = new setSessionParameters();
    //sessionParams.viewSettings = new viewSettings
    //{
    //    appType = "Custom",
    //    forceLogoutSession = false,
    //    idleTimeOut = 600,
    //    rollingPeriod = rollingPeriod.Minutes5,
    //    shiftStart = 28800000,
    //    statisticsRange = statisticsRange.CurrentDay,
    //    timeZone = -25200000
    //};


        getStatistics statistics = new getStatistics();

        statistics.statisticTypeSpecified = true;
        statistics.statisticType = statisticType.AgentStatistics;
        statistics.columnNames = null;

        getStatisticsResponse resp = new getStatisticsResponse();

        statistics statistics_return = resp.@return;

        int usernameIdx = agentStatisticsColumns["Username"];

        foreach (row r in statistics_return.rows)
        {
            Output0Buffer.Username = r.values[usernameIdx];
            //string log = r.values[usernameIdx];

            //Output0Buffer.Username = log;
        }

}

任何帮助将不胜感激!

【问题讨论】:

  • 我个人认为,如果您只是将 Web 服务数据加载到表中,那么如果您只是构建一个控制台应用程序来完成它会容易得多。 SSIS 脚本任务缺少许多有用的调试工具,并且在部署时存在一些问题(它可能已修复,但上次我使用它时,您需要对已部署服务器上 C 驱动器上的临时驱动器的特殊管理员权限)。无论如何..你能告诉错误发生在哪一行吗?
  • 感谢您的回复。该错误似乎发生在 int usernameIdx = agentStatisticsColumns["Username"];线。我一直在考虑不使用 SSIS,但我通过 Power BI 建立此 Web 服务的尝试失败了。最终目标是使用导出到 SQL Server 的数据在 Power BI 中创建视觉对象。因此,我为什么选择 SSIS,但如果我不能解决这个问题,我可能不得不寻找 C 计划。
  • 在 power bi 中执行此操作是最不实用和可维护的方式。 SSIS 是一种更好的方法,但脚本任务缺乏可用性。 C# 控制台应用程序是最强大的方法,但您必须熟悉在系统构建中使用它。无论如何...您的错误是在agentStatisticsColumns 数组中找不到“用户名”。这并不奇怪,因为我没有看到它在您的代码中的任何地方加载。这是为了表示来自网络服务的数据吗?
  • 是的,username是webservice的getstatistics方法的一个字段。
  • 在该代码中,变量agentStatisticsColumns 没有任何内容。没有代码将任何内容加载到其中。您需要一些使用getStatisticsResponse(其中确实有一些东西)的代码以某种方式填充agentStatisticsColumns。如果您可以在运行时检查 getStatisticsResponse 的内容,将会有所帮助。不确定您是否可以在 SSIS 脚本编辑器中执行此操作

标签: c# dictionary ssis script-component


【解决方案1】:

您完全正确,这是我的愚蠢疏忽。我需要合并该领域: 公共静态 WsSupervisorService supervisorService = null;

这样我就可以包装 getStatisticsResponse resp = supervisorService.getStatistics(statistics);有一个实际的 VALUE。

谢谢尼克!

 public Dictionary<string, int> agentStatisticsColumns = new Dictionary<string, int>();
    public static WsSupervisorService supervisorService = null;
    public static void Main(string[] args)
    {
        supervisorService = new WsSupervisorService();
        setSessionParameters sessionParams = new setSessionParameters();

        sessionParams.viewSettings = new viewSettings
        {
            appType = "Custom",
            forceLogoutSession = false,
            idleTimeOut = 600,
            rollingPeriod = rollingPeriod.Minutes5,
            shiftStart = 28800000,
            statisticsRange = statisticsRange.CurrentDay,
            timeZone = -25200000
        };

        getStatistics statistics = new getStatistics();
        statistics.statisticTypeSpecified = true;
        statistics.statisticType = statisticType.AgentStatistics;
        statistics.columnNames = null;

        try
        {
            getStatisticsResponse resp = supervisorService.getStatistics(statistics);
        }
        catch (Exception)
        {

            throw;
        }
    }

【讨论】:

  • 感谢您返回解决方案。如果您可以在此处发布最终代码,那将非常方便。那我确定接受你自己的答案就OK了
猜你喜欢
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 2016-08-14
  • 1970-01-01
  • 2022-09-28
  • 1970-01-01
相关资源
最近更新 更多