Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在充当目标的SSIS脚本组件中动态获取列名_C#_Ssis - Fatal编程技术网

C# 在充当目标的SSIS脚本组件中动态获取列名

C# 在充当目标的SSIS脚本组件中动态获取列名,c#,ssis,C#,Ssis,好的,我正在使用SSIS脚本组件作为目标编写一个avro文件。因为AVRO也需要一个模式,所以我需要定义这个模式。当我手动定义模式时,它工作得很好。但是我有10-12个数据流任务,我不想显式地编写模式。我试图看看我是否可以使用自动生成的BufferWrapper来查看我是否可以从那里读取,但我不能,它总是返回空白 public override void Input0_ProcessInputRow(Input0Buffer Row) { if (counter == 0) {

好的,我正在使用SSIS脚本组件作为目标编写一个avro文件。因为AVRO也需要一个模式,所以我需要定义这个模式。当我手动定义模式时,它工作得很好。但是我有10-12个数据流任务,我不想显式地编写模式。我试图看看我是否可以使用自动生成的BufferWrapper来查看我是否可以从那里读取,但我不能,它总是返回空白

public override void Input0_ProcessInputRow(Input0Buffer Row)
{

    if (counter == 0)
    {
        Type myType = typeof(Input0Buffer);

        // Get the fields of the specified class.
        FieldInfo[] myField = myType.GetFields();
     }
  //Processing logic
 }
我试过贴出的解决方案,也读过了。 但一切都是空白的

public override void Input0_ProcessInputRow(Input0Buffer Row)
{

    if (counter == 0)
    {
        Type myType = typeof(Input0Buffer);

        // Get the fields of the specified class.
        FieldInfo[] myField = myType.GetFields();
     }
  //Processing logic
 }
我也遇到过。这可能是原因吗?如果答案中的解释是正确的,这不可能吗

所以,在我的 public override void PreExecute(),我有如下内容:

Schema = @"{
                        ""type"":""record"",
                        ""name"":""Microsoft.Hadoop.Avro.Specifications.Counterparts"",
                        ""fields"":
                            [
                               { ""name"":""CounterpartID"", ""type"":""int"" },
                               { ""name"":""CounterpartFirstDepositDate"",  ""type"":[""string"",""null""] },
                               { ""name"":""CounterpartFirstTradeDate"",""type"":[""string"",""null""] },
                               { ""name"":""ClientSegmentReportingID"",""type"":[""int"",""null""] },
                               { ""name"":""ClientSegmentReportingName"", ""type"":[""string"",""null""] },
                               { ""name"":""ContractID"", ""type"":[""int"",""null""] },
                               { ""name"":""ContractFirstDepositDate"", ""type"":[""string"",""null""] },
                               { ""name"":""ContractFirstTradeDate"",""type"":[""string"",""null""] },
                               { ""name"":""ContractClosingOffice"",""type"":[""string"",""null""] },
                               { ""name"":""LeadCreationDate"", ""type"":[""string"",""null""] },
                               { ""name"":""ContractCountryOfResidence"", ""type"":[""string"",""null""] }
                            ]
                    }";

}
我不是手动定义所有此架构,而是检查是否可以从BufferWrapper生成它,但返回为空:

var fields = typeof(Input0Buffer).GetFields().Select(m => new
{
    Name = m.Name,
    Type = m.FieldType
}).ToList();
而且,如果我这样做,它也会返回空白

类型myType=typeof(Input0Buffer)

早些时候,我将这些新方法放在Pre-Execute中,但后来我想,缓冲区可能还没有初始化,所以我将其移动到Input0\u ProcessInputRow方法中,并确保使用计数器变量只触发一次,并使此代码仅在计数器=0时运行,但即使返回空

public override void Input0_ProcessInputRow(Input0Buffer Row)
{

    if (counter == 0)
    {
        Type myType = typeof(Input0Buffer);

        // Get the fields of the specified class.
        FieldInfo[] myField = myType.GetFields();
     }
  //Processing logic
 }
这不可能是因为你的原因吗


当它谈到它被保护,也不能从自动生成的类外部访问时。

我终于在这里找到了答案:


我最终可以从脚本组件中获得列和数据类型的列表。我只会第一次运行它(使用计数器变量)。

如果只创建一次表,我会在数据库中而不是在c#中编写代码。您可以使用SQL Server Management Studio并使用资源管理器右键单击数据库/表,然后使用选项创建表定义以查看代码示例。您好,我不是在数据库中创建表。我正在编写一个AVRO文件,它需要一个模式。我有一个OLEDB源代码,它从SQL server获取数据,目的是从该源代码写入AVRO文件。正如我所说,我正在努力使这个动态,因为这不是我要创建的唯一一个AVRO文件。还有20个。所以,我不需要特定的定义。模式格式是JSON,所以任何可以生成JSON的网络类/库都可以。请参阅Wiki:问题不在于JSON或AVRO。问题是如何从SSIS InputBuffer中的脚本组件动态获取列列表,并使用该列表为AVRO生成模式。感兴趣的是从SSI的InputBuffer动态确定输入列。无论如何,我已经找到了答案并将发布。您可以从c#获取信息,而不是使用带有GetSchema方法的脚本: