具有ScriptComponent的BIML会产生软件包,但无法在SSDT中打开

时间:2019-04-30 21:53:27

标签: biml

更新:修改了帖子,以包含可能重现此问题的最简单解决方案。

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

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

脚本组件没有很多BIML示例,但是我的解决方案是遵循Varigence Doca blog from Joost的混合。

当我编译BIML时,它会毫无错误地创建包;但是,当我打开包装时,收到错误消息:

  

“值不落在预期范围内”

下面是该代码的精简版本,对于重现该错误而言,这是最低要求。应该与将代码复制到.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>

1 个答案:

答案 0 :(得分:0)

我已通过将SSIS项目属性切换为目标SQL Server 2016来解决了此问题,默认情况下为目标SQL Server 2017。

这似乎是Varigence产品中的错误,因为此forum post确认其他人正在遇到此问题。除了在2019年2月“向我们发送回购”外,Varigence均未提供任何更新。Varigence声明有一个“预览版本”可解决此问题,但预览版本未链接到该帖子并跟踪该帖子中的要求预览版本的后续帖子没有答案。我猜是this is the preview build。我尝试了2019年预览版,但没有解决问题。 Scott Currie的帖子提到了预览版本修复与我的情况不符的情况,他指出当您使用低级平台定位(即使用VS 2017定位SQL 2016)时会发生此问题。我没有这样做,我在使用VS2017定位到SQL2017。

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

  

无法创建用户组件,请确保至少有一个类   标有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>