Biml(或 SSIS)似乎不想自动识别行分隔符。如果没有在列列表的最后一列上手动设置为预期行分隔符的列,SSIS 不会为行正确设置分隔符。我猜 SSIS 只是暗示行分隔符,即使它是在连接属性中设置的。除了围绕问题编写并将最后一列的分隔符设置为预期的行分隔符(参见下面的“T”列)之外,任何人都知道解决此问题的方法吗?
我检查了输出 Connection 的属性,它正确地将“RowDelimiter”声明为 CRLF,但是如果您查看
这是 Biml 文件:
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Connections>
<OleDbConnection Name="Source" ConnectionString="Provider=SQLNCLI11;Server=localhost;Initial Catalog=test;Integrated Security=SSPI;">
</OleDbConnection>
<FlatFileConnection Name="Created" FilePath="D:\\created.dat" FileFormat="Changed">
<Expressions>
<Expression PropertyName="ConnectionString">@[$Package::FileDropRoot] + "\\"+REPLACE((DT_WSTR, 10)(DT_DBDATE)GETDATE(),"-","") + "." + "created.dat"</Expression>
</Expressions>
</FlatFileConnection>
</Connections>
<FileFormats>
<FlatFileFormat Name="Changed" ColumnNamesInFirstDataRow="true" HeaderRowDelimiter="CRLF" RowDelimiter="CRLF">
<Columns>
<Column Name="col1" DataType="String" Delimiter="Comma" ColumnType="Delimited" />
<Column Name="col2" DataType="String" Delimiter="Comma" ColumnType="Delimited"/>
<!-- this must be here in order to terminate the row -->
<Column Name="T" DataType="String" Delimiter="Comma" ColumnType="CRLF"/>
</Columns>
</FlatFileFormat>
</FileFormats>
<Packages>
<Package Name="Test" ConstraintMode="Linear" ProtectionLevel="EncryptSensitiveWithUserKey">
<Tasks>
<Dataflow Name="Test">
<Transformations>
<OleDbSource Name="Select Stagement" ConnectionName="Source">
<DirectInput>
Select * From Test
</DirectInput>
</OleDbSource>
<FlatFileDestination Name="UpdateFile" ConnectionName="Created">
</FlatFileDestination>
</Transformations>
</Dataflow>
</Tasks>
<Parameters>
<Parameter Name="FileDropRoot" DataType="String">D:\FileDrop</Parameter>
</Parameters>
</Package>
</Packages>
</Biml>
这是上面 T 列的 SSIS“代码”,请注意指定了行分隔符(导出文件中的换行符):
<DTS:ConnectionManager DTS:CreationName="FLATFILE" DTS:DTSID="{9CDCB838-2A42-4CCA-A59C-DC60E9B3A967}" DTS:ObjectName="Created" DTS:refId="Package.ConnectionManagers[Created]">
<DTS:ObjectData>
<DTS:ConnectionManager DTS:CodePage="1252" DTS:ColumnNamesInFirstDataRow="True" DTS:ConnectionString="D:\\created.dat" DTS:Format="Delimited" DTS:HeaderRowDelimiter="_x000D__x000A_" DTS:LocaleID="1033" DTS:RowDelimiter="_x000D__x000A_" DTS:TextQualifier="_x003C_none_x003E_" DTS:Unicode="True">
<DTS:FlatFileColumns>
<DTS:FlatFileColumn DTS:ColumnDelimiter="_x002C_" DTS:ColumnType="Delimited" DTS:CreationName="" DTS:DataType="303" DTS:DTSID="{D64391D4-4551-44E9-8539-4C473EB700AA}" DTS:ObjectName="col1" DTS:TextQualified="True">
</DTS:FlatFileColumn>
<DTS:FlatFileColumn DTS:ColumnDelimiter="_x002C_" DTS:ColumnType="Delimited" DTS:CreationName="" DTS:DataType="303" DTS:DTSID="{974ED1AD-7D72-4A65-A877-BADEC09DAF20}" DTS:ObjectName="col2" DTS:TextQualified="True">
</DTS:FlatFileColumn>
<DTS:FlatFileColumn DTS:ColumnDelimiter="_x000D__x000A_" DTS:ColumnType="Delimited" DTS:CreationName="" DTS:DataType="303" DTS:DTSID="{4347C3C1-39BD-40B1-B38F-526730FE7BFB}" DTS:ObjectName="T" DTS:TextQualified="True">
</DTS:FlatFileColumn>
</DTS:FlatFileColumns>
</DTS:ConnectionManager>
</DTS:ObjectData>
<DTS:PropertyExpression DTS:Name="ConnectionString">@[$Package::FileDropRoot] + "\\"+REPLACE((DT_WSTR, 10)(DT_DBDATE)GETDATE(),"-","") + "." + "created.dat"</DTS:PropertyExpression>
</DTS:ConnectionManager>
这是上面没有 T 列的 SSIS“代码”,请注意指定了行分隔符(导出文件中没有换行符):
<DTS:ConnectionManager DTS:CreationName="FLATFILE" DTS:DTSID="{79E9C576-FD53-4D4F-A07C-AED8D4CE72E6}" DTS:ObjectName="Created" DTS:refId="Package.ConnectionManagers[Created]">
<DTS:ObjectData>
<DTS:ConnectionManager DTS:CodePage="1252" DTS:ColumnNamesInFirstDataRow="True" DTS:ConnectionString="D:\\created.dat" DTS:Format="Delimited" DTS:HeaderRowDelimiter="_x000D__x000A_" DTS:LocaleID="1033" DTS:RowDelimiter="_x000D__x000A_" DTS:TextQualifier="_x003C_none_x003E_" DTS:Unicode="True">
<DTS:FlatFileColumns>
<DTS:FlatFileColumn DTS:ColumnDelimiter="_x002C_" DTS:ColumnType="Delimited" DTS:CreationName="" DTS:DataType="303" DTS:DTSID="{BBCA22D2-5D3E-47AC-AA0A-413C0C1A5CB2}" DTS:ObjectName="col1" DTS:TextQualified="True">
</DTS:FlatFileColumn>
<DTS:FlatFileColumn DTS:ColumnDelimiter="_x002C_" DTS:ColumnType="Delimited" DTS:CreationName="" DTS:DataType="303" DTS:DTSID="{44E567E4-BE78-432C-A8AC-C388E8BCFADC}" DTS:ObjectName="col2" DTS:TextQualified="True">
</DTS:FlatFileColumn>
</DTS:FlatFileColumns>
</DTS:ConnectionManager>
</DTS:ObjectData>
<DTS:PropertyExpression DTS:Name="ConnectionString">@[$Package::FileDropRoot] + "\\"+REPLACE((DT_WSTR, 10)(DT_DBDATE)GETDATE(),"-","") + "." + "created.dat"</DTS:PropertyExpression>
</DTS:ConnectionManager>
这是我用来在数据库连接上创建表的脚本
CREATE TABLE Test(col1 varchar(25),col2 varchar(25))
INSERT INTO Test
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2' UNION all
SELECT '1','2'