带有 ScriptComponent 的 BIML 生成包但不会在 SSDT 中打开

BIML with ScriptComponent Produces Package but won't open in SSDT

更新:已修改 post 以包括可能重现该问题的最简单解决方案。

我正在努力使用 BIML 中的 ScriptComponentProject。我正在使用 VS 2017 和 BIML Express 2018 最新版本。

我正在尝试创建一个脚本组件,它将使用此 blog post 中列出的策略检索错误描述和有问题的列名称。

脚本组件的 BIML 示例不多,但我的解决方案是以下 Varigence Doc & a blog from Joost.

的组合

当我编译 BIML 时,它创建的包没有错误;但是,当我打开包裹时收到错误消息:

"Value Does not fall withing the expected range"

下面是代码的精简版本,它是重现错误的最低限度。应该像将代码复制到 .biml 文件并生成 SSIS 包一样简单。该示例从一列 CSV 文件中读取,将源中的列转换为整数。数据转换错误被定向到脚本组件,然后将有问题的列和错误描述列添加到输出缓冲区,然后将此输出写入平面文件目标。

如有任何帮助,我们将不胜感激。

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <FlatFileConnection Name="Errors" FilePath="C:\Users\username\Desktop\BasicSSISErrors.csv" FileFormat="Errors" />
        <FlatFileConnection Name="Source" FilePath="C:\Users\username\Desktop\BasicSSIS.csv" FileFormat="Source" />
    </Connections>
    <Packages>
        <Package Name="PackageFromBIML" Language="None" ConstraintMode="LinearOnCompletion" ProtectionLevel="EncryptSensitiveWithUserKey">
            <Tasks>
                <Dataflow Name="Data Flow Task">
                    <Transformations>
                        <FlatFileSource Name="Flat File Source" LocaleId="None" FileNameColumnName="" ConnectionName="Source" />
                        <DataConversion Name="Data Conversion">
                            <DataflowOverrides>
                                <OutputPath OutputPathName="Output">
                                    <Columns>
                                        <Column ErrorRowDisposition="RedirectRow" TruncationRowDisposition="RedirectRow" ColumnName="Converted" />
                                    </Columns>
                                </OutputPath>
                            </DataflowOverrides>
                            <Columns>
                                <Column SourceColumn="Integers" TargetColumn="Converted" DataType="SByte" />
                            </Columns>
                        </DataConversion>
                        <ScriptComponentTransformation Name="Script Component" ProjectCoreName="SC_a8f35334a2234702a5f92abdcbedb4e4">
                            <InputPath OutputPathName="Data Conversion.Error" />
                            <ScriptComponentProjectReference ScriptComponentProjectName="SC_a8f35334a2234702a5f92abdcbedb4e4" />
                        </ScriptComponentTransformation>
                        <FlatFileDestination Name="Flat File Destination" LocaleId="None" ConnectionName="Errors">
                            <Header></Header>
                        </FlatFileDestination>
                    </Transformations>
                </Dataflow>
            </Tasks>
        </Package>
    </Packages>
    <FileFormats>
        <FlatFileFormat Name="Errors" CodePage="1252" TextQualifier="_x003C_none_x003E_" ColumnNamesInFirstDataRow="true" RowDelimiter="">
            <Columns>
                <Column Name="Integers" Length="50" DataType="AnsiString" Delimiter="Comma" MaximumWidth="50" />
                <Column Name="ErrorCode" Delimiter="Comma" />
                <Column Name="ErrorColumn" Delimiter="Comma" />
                <Column Name="ErrorColumnName" DataType="AnsiString" Delimiter="Comma" />
                <Column Name="ErrorDescription" DataType="AnsiString" Delimiter="CRLF" />
            </Columns>
        </FlatFileFormat>
        <FlatFileFormat Name="Source" CodePage="1252" TextQualifier="_x003C_none_x003E_" ColumnNamesInFirstDataRow="true" RowDelimiter="">
            <Columns>
                <Column Name="Integers" Length="50" DataType="AnsiString" Delimiter="CRLF" MaximumWidth="50" />
            </Columns>
        </FlatFileFormat>
    </FileFormats>
    <ScriptProjects>
        <ScriptComponentProject Name="SC_a8f35334a2234702a5f92abdcbedb4e4" ProjectCoreName="SC_a8f35334a2234702a5f92abdcbedb4e4.csproj">
            <OutputBuffers>
                <OutputBuffer Name="Output 0">
                    <Columns>
                        <Column Name="ErrorColumnName" Length="500" DataType="AnsiString" CodePage="1252" />
                        <Column Name="ErrorDescription" Length="500" DataType="AnsiString" CodePage="1252" />
                    </Columns>
                </OutputBuffer>
            </OutputBuffers>
            <InputBuffer Name="Input 0">
                <Columns>
                    <Column Name="ErrorCode" />
                    <Column Name="ErrorColumn" />
                </Columns>
            </InputBuffer>
            <AssemblyReferences>
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript.dll" />
                   <AssemblyReference AssemblyPath="System.dll" />
                   <AssemblyReference AssemblyPath="System.AddIn.dll" />
                   <AssemblyReference AssemblyPath="System.Data.dll" />
                   <AssemblyReference AssemblyPath="System.Xml.dll" />
            </AssemblyReferences>
                        <Files>
       <!-- Left alignment of .Net script to get a neat layout in package-->
            <File Path="AssemblyInfo.cs">
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("SC_a8f35334a2234702a5f92abdcbedb4e4.csproj")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SC_a8f35334a2234702a5f92abdcbedb4e4.csproj")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.0.*")]
                           </File>

                           <File Path="main.cs">
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public partial class ScriptMain : UserComponent
{
  public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Row.ErrorDescription = this.ComponentMetaData.GetErrorDescription(Row.ErrorCode);
        IDTSComponentMetaData130 componentMetaData = this.ComponentMetaData as IDTSComponentMetaData130;
        Row.ErrorColumnName = componentMetaData.GetIdentificationStringByID(Row.ErrorColumn);
    }
}
                </File>
            </Files>
        </ScriptComponentProject>
    </ScriptProjects>
</Biml>

我通过将 SSIS 项目属性切换到目标 SQL Server 2016 解决了这个问题,它默认为目标 SQL Server 2017。

这似乎是 Varigence 产品中的一个错误,因为 forum post confirms others are experiencing the issue. No updates from Varigence other than "send us a repo" back in February 2019. Varigence states there is a "preview build" which fixes the issue but the preview build is not linked to and follow up posts in the thread which request the preview build have gone unanswered. I'm guessing this is the preview build。我尝试了 2019 预览版,但没有解决问题。来自 Scott Currie 的 post 提到预览版本修复的内容与我的情况不符,他说问题发生在你定位到下层平台时,即使用 VS 2017 来定位 SQL 2016。我是不这样做,我正在使用 VS2017 来定位 SQL 2017。

在此之后我还遇到了另一个问题,我收到了错误:

Cannot create user component make sure there is at least one class marked with SsisScriptTaskEntryPointattribute

我通过添加对 Microsoft.SqlServer.ScriptTask.dll 的程序集引用来更正此问题。此程序集引用未包含在 Varigence 示例中。

完整修正方案如下:

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <FlatFileConnection Name="Errors" FilePath="C:\Users\username\Desktop\BasicSSISErrors.csv" FileFormat="Errors" />
        <FlatFileConnection Name="Source" FilePath="C:\Users\username\Desktop\BasicSSIS.csv" FileFormat="Source" />
    </Connections>
    <ScriptProjects>
        <ScriptComponentProject ScriptLanguage="CSharp"  Name="SCR - ErrorHelper" ProjectCoreName="SC_a8f35334a2234702a5f92abdcbedb4e4">
            <AssemblyReferences>
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost.dll" />
                    <AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
                   <AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript.dll" />
                   <AssemblyReference AssemblyPath="System.dll" />
                    <AssemblyReference AssemblyPath="System.Data.dll" />
                    <AssemblyReference AssemblyPath="System.Xml.dll" />
                    <AssemblyReference AssemblyPath="System.Core.dll" />
                   <AssemblyReference AssemblyPath="System.AddIn.dll" />
                   <AssemblyReference AssemblyPath="System.Data.dll" />
                   <AssemblyReference AssemblyPath="System.Xml.dll" />
            </AssemblyReferences>
                        <Files>
       <!-- Left alignment of .Net script to get a neat layout in package-->
            <File Path="AssemblyInfo.cs">
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("SC_2bca370105ff4883a705860bac68cfba.csproj")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Varigence")]
[assembly: AssemblyProduct("SC_2bca370105ff4883a705860bac68cfba.csproj")]
[assembly: AssemblyCopyright("Copyright @ Varigence 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]


[assembly: AssemblyVersion("1.0.*")]</File>
        <File Path="main.cs">
using System;
using System.Data;
using System.Linq;
using System.Net;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
  public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Row.ErrorDescription = this.ComponentMetaData.GetErrorDescription(Row.ErrorCode);

        var componentMetaData130 = this.ComponentMetaData as IDTSComponentMetaData130;
        if (componentMetaData130 != null)
        {
            // 0 means no specific column is identified by ErrorColumn, this time.
            if (Row.ErrorColumn == 0)
            {
                Row.ErrorColumnName = "Check the row for a violation of a foreign key constraint. No specific column is identified by ErrorColum";
            }
            else
            {
                Row.ErrorColumnName = componentMetaData130.GetIdentificationStringByID(Row.ErrorColumn);
            }
        }
    }
}
                </File>
            </Files>
        <OutputBuffers>
                <OutputBuffer Name="Output0">
                    <Columns>
                        <Column Name="ErrorColumnName" Length="500" DataType="AnsiString" CodePage="1252" />
                        <Column Name="ErrorDescription" Length="500" DataType="AnsiString" CodePage="1252" />
                    </Columns>
                </OutputBuffer>
            </OutputBuffers>
            <InputBuffer Name="Input0">
                <Columns>
                    <Column Name="ErrorCode" />
                    <Column Name="ErrorColumn" />
                </Columns>
            </InputBuffer>
        </ScriptComponentProject>
    </ScriptProjects>
    <Packages>
        <Package Name="PackageFromBIML" Language="None" ConstraintMode="LinearOnCompletion" ProtectionLevel="EncryptSensitiveWithUserKey">
            <Tasks>
                <Dataflow Name="Data Flow Task">
                    <Transformations>
                        <FlatFileSource Name="Flat File Source" LocaleId="None" FileNameColumnName="" ConnectionName="Source" />
                        <DataConversion Name="Data Conversion">
                            <DataflowOverrides>
                                <OutputPath OutputPathName="Output">
                                    <Columns>
                                        <Column ErrorRowDisposition="RedirectRow" TruncationRowDisposition="RedirectRow" ColumnName="Converted" />
                                    </Columns>
                                </OutputPath>
                            </DataflowOverrides>
                            <Columns>
                                <Column SourceColumn="Integers" TargetColumn="Converted" DataType="SByte" />
                            </Columns>
                        </DataConversion>
                        <ScriptComponentTransformation Name="Script Component" ProjectCoreName="SC_a8f35334a2234702a5f92abdcbedb4e4">
                            <InputPath OutputPathName="Data Conversion.Error" />
                            <ScriptComponentProjectReference ScriptComponentProjectName="SCR - ErrorHelper" />
                        </ScriptComponentTransformation>
                        <FlatFileDestination Name="Flat File Destination" LocaleId="None" ConnectionName="Errors">
                            <Header></Header>
                        </FlatFileDestination>
                    </Transformations>
                </Dataflow>
            </Tasks>
        </Package>
    </Packages>
    <FileFormats>
        <FlatFileFormat Name="Errors" CodePage="1252" TextQualifier="_x003C_none_x003E_" ColumnNamesInFirstDataRow="true" RowDelimiter="">
            <Columns>
                <Column Name="Integers" Length="50" DataType="AnsiString" Delimiter="Comma" MaximumWidth="50" />
                <Column Name="ErrorCode" Delimiter="Comma" />
                <Column Name="ErrorColumn" Delimiter="Comma" />
                <Column Name="ErrorColumnName" DataType="AnsiString" Delimiter="Comma" />
                <Column Name="ErrorDescription" DataType="AnsiString" Delimiter="CRLF" />
            </Columns>
        </FlatFileFormat>
        <FlatFileFormat Name="Source" CodePage="1252" TextQualifier="_x003C_none_x003E_" ColumnNamesInFirstDataRow="true" RowDelimiter="">
            <Columns>
                <Column Name="Integers" Length="50" DataType="AnsiString" Delimiter="CRLF" MaximumWidth="50" />
            </Columns>
        </FlatFileFormat>
    </FileFormats>

</Biml>