FixedWidth binary columns in FlatFile Connection generated with BIML gets OutputColumnWidth at 0 (zero)

72 views Asked by At

When I preview my BIML, this is how my columns are defined:

    <FlatFileFormat Name="(FFF) MyFixedWidthFlatFile" CodePage="1252" FlatFileType="FixedWidth" RowDelimiter="" IsUnicode="false" TextQualifier="_x003C_none_x003E_">
  <Columns>
    <Column Name="HEADER" DataType="Binary" Length="2" Delimiter="" TextQualified="false" ColumnType="FixedWidth" MaximumWidth="2"></Column>
    <Column Name="DESCRIPT" DataType="AnsiString" Length="30" Delimiter="" TextQualified="false" ColumnType="FixedWidth" MaximumWidth="30"></Column>

The package is generated succesfully, however, the OutputColumnWidth in the Flat File Connection is not set for the binary columns.

Flat File Connection properties

The String columns are correct.

enter image description here

What am I missing?

Thank you!

1

There are 1 answers

0
Simon Blais On

So I did a thing. The following code edits the DTSX file to add the missing attributes. BEWARE: if you intend to reuse this code, it will change your package on save, not on package generation. If you're not comfortable with that, wrap it inside an EXE. Also, it could break your package so be sure you can generate it again or that you have a backup. The package and the BIML file should be in the same directory.

<#@ template tier="999" language="VB" optionexplicit="False" #>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.IO" #>
<#
Dim filename as string = "package.dtsx"
Dim packageFile As New XmlDocument()
packageFile.Load(Path.GetDirectoryName(Host.templateFile) & "\" & filename)
Dim nodes as XmlNodeList = packageFile.GetElementsByTagName("DTS:FlatFileColumn")
If nodes IsNot Nothing Then
    For each node in nodes
        If node.Attributes("DTS:DataType").Value = "128"Then
            If node.Attributes("DTS:MaximumWidth") Is Nothing Then
                Dim mw as XmlAttribute = packageFile.CreateAttribute("MaximumWidth","www.microsoft.com/SqlServer/Dts")
                mw.Value = node.Attributes("DTS:ColumnWidth").Value
                node.Attributes.InsertAfter(mw,node.Attributes("DTS:ColumnWidth"))
                #>
                <<#="Node " & node.Attributes("DTS:ObjectName").Value & " has changed."#>/>
                <#
            End If
        End If
    Next
End If
packageFile.Save(Path.GetDirectoryName(Host.templateFile) & "\" & filename)
#>
</Biml>