The header row is delimited by a comma. Tab {t} The header row is delimited by a tab.
1. Create a new SSIS package and a new Data Flow Task within the package. 2. Drag the Flat File Source adapter from the Toolbox onto the Data Flow workspace and then double-click the Flat File Source to open the Flat File Source Editor.
The Flat File source reads data from a text file. The text file can be in delimited, fixed width, or mixed format. Delimited format uses column and row delimiters to define columns and rows. Fixed width format uses width to define columns and rows.
Solution: First of all, do not right click on the connection manager and select "parameterize". Sounds silly but it will eventually be parameterized. Now you go within each connection manager in the properties window and click on the ellipse button next to Expressions (highlighted).
SSIS fails to read the file and displays the below warning due to the column delimiter Ç
("c" with cedilla) and not
due to the line delimiter {LF}
(Line Feed).
[Read flat file [1]] Warning: The end of the data file was reached while
reading header rows. Make sure the header row delimiter and the number of
header rows to skip are correct.
Here is a sample SSIS package that shows how to resolve the issue using Script Component
and at the end there is another example that simulates your issue.
Below sample package is written in SSIS 2008 R2
. It reads a flat file with row delimiter {LF}
as a single column value; then splits the data using Script Component
to insert the information into a table in SQL Server 2008 R2
database.
Use Notepad++ to create a simple flat file with few rows. The below sample file has Product Id and List Price information on each row separated by Ç
as column delimiter and each row ends with {LF}
delimiter.
On the Notepad++, click Encoding
and then click Encoding in UTF-8
to save the flat file in UTF-8
encoding.
The sample will use an SQL Server 2008 R2
database named Sora
. Create a new table named dbo.ProductListPrice
using the below given script. SSIS will insert the flat file data into this table.
USE Sora;
GO
CREATE TABLE dbo.ProductListPrice
(
ProductId nvarchar(30) NOT NULL
, ListPrice numeric(12,2) NOT NULL
);
GO
Create an SSIS package using Business Intelligence Development Studio (BIDS) 2008 R2. Name the package as SO_6268205.dtsx
. Create a data source named Sora.ds
to connect to the database Sora
in SQL Server 2008 R2.
Right-click anywhere inside the package and then click Variables
to view the variables pane. Create a new variable named ColumnDelimiter
of data type String
in the package scope SO_6268205
and set the variable with the value Ç
Right-click on the Connection Managers
and click New Flat File Connection...
to create a connection to read the flat file.
On the General
page of the Flat File Connection Manager Editor, perform the following actions:
ProductListPrice
Flat file connection manager to read product list price information.
C:\Siva\StackOverflow\Files\6268205\ProductListPrice.txt
{LF}
from Header Row Delimiter
Column names in the first data row
Columns
pageOn the Columns
page of the Flat File Connection Manager Editor, verify that the Column delimiter
is blank and disabled. Click Advanced
page.
On the Advanced
page of the Flat File Connection Manager Editor, perform the following actions.
LineData
{LF}
Unicode string [DT_WSTR]
255
Preview
page.On the Preview
page of the Flat File Connection Manager Editor, verify that the displayed data looks correct and click OK
.
You will see the data source Sora and the flat file connection manager ProductListPrice on the Connection Managers
tab at the bottom of the package.
Drag and drop Data Flow Task
onto the Control Flow tab of the package and name it as File to database - Without Cedilla delimiter
Double-click the Data Flow Task to switch the view to the Data Flow
tab on the package. Drag and drop a Flat File Source
on the Data Flow tab. Double-click the Flat File Source to open Flat File Source Editor
.
On the Connection Manager
page of the Flat File Source Editor, select the Flat File Connection Manager ProductListPrice
and click Columns page.
On the Columns
page of the Flat File Source Editor, check the column LineData
and click OK
.
Drag and drop a Script Component
onto the Data Flow tab below the Flat File Source, select Transformation
and click OK
. Connect the green arrow from Flat File Source to Script Component. Double-click Script Component to open Script Transformation Editor
.
Click Input Columns on Script Transformation Editor and select LineData
column. Click Inputs and Outputs page.
On the Inputs and Outputs
page of the Script Transformation Editor, perform the following actions.
SplitDataOutput
Add Column
. Repeat this again to add another column.ProductId
Unicode string [DT_WSTR]
30
On the Inputs and Outputs
page of the Script Transformation Editor, perform the following actions.
ListPrice
numeric [DT_NUMERIC]
12
2
On the Script
page of the Script Transformation Editor, perform the following actions.
User::ColumnDelimiter
Edit Script...
Paste the below C# in the Script Editor. The script performs the following tasks.
Ç
defined in the variable User::ColumnDelimiter, the method FlatFileInput_ProcessInputRow
splits the incoming value and assigns it to the two output columns defined in the Script Component transformation.using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void PreExecute()
{
base.PreExecute();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void FlatFileInput_ProcessInputRow(FlatFileInputBuffer Row)
{
const int COL_PRODUCT = 0;
const int COL_PRICE = 1;
char delimiter = Convert.ToChar(this.Variables.ColumnDelimiter);
string[] lineData = Row.LineData.ToString().Split(delimiter);
Row.ProductId = String.IsNullOrEmpty(lineData[COL_PRODUCT])
? String.Empty
: lineData[COL_PRODUCT];
Row.ListPrice = String.IsNullOrEmpty(lineData[COL_PRICE])
? 0
: Convert.ToDecimal(lineData[COL_PRICE]);
}
}
Drag and drop OLE DB Destination
onto the Data Flow tab. Connect the green arrow from Script Component to OLE DB Destination. Double-click OLE DB Destination to open OLE DB Destination Editor
.
On the Connection Manager
page of the OLE DB Destination Editor, perform the following actions.
Sora
from OLE DB Connection Manager
Table or view - fast load
from Data access mode
[dbo].[ProductListPrice]
from Name of the table or the view
Click Mappings
page on the OLE DB Destination Editor would automatically map the columns if the input and output column names are same. Click OK
.
Data Flow tab should look something like this after configuring all the components.
Execute the query select * from dbo.ProductListPrice
in the SQL Server Management Studio (SSMS) to find the number of rows in the table. It should be empty before executing the package.
Execute the package. You will notice that the package successfully processed 9 rows. The flat file contains 10 lines but the first row is header with column names.
Execute the query select * from dbo.ProductListPrice
in the SQL Server Management Studio (SSMS) to find the 9 rows successfully inserted into the table. The data should match with flat file data.
The above example illustrated how to manually split the data using Script Component because the Flat File Connection Manager encounters error when configured the column delimiter Ç
This example shows a separate Flat File Connection Manager configured with column delimiter Ç
, which executes but encounters a warning and does not process any lines.
Right-click on the Connection Managers
and click New Flat File Connection...
to create a connection to read the flat file. On the General
page of the Flat File Connection Manager Editor, perform the following actions:
ProductListPrice_Cedilla
Flat file connection manager with Cedilla column delimiter.
C:\Siva\StackOverflow\Files\6268205\ProductListPrice.txt
Select the flat file path.{LF}
from Header Row Delimiter
Column names in the first data row
Columns
pageOn the Columns
page of the Flat File Connection Manager Editor, perform the following actions:
{LF}
Reset Columns
Ç
Advanced
pageOn the Advanced
page of the Flat File Connection Manager Editor, perform the following actions:
ProductId
Ç
Unicode string [DT_WSTR]
30
ListPrice
On the Advanced
page of the Flat File Connection Manager Editor, perform the following actions:
ListPrice
{LF}
numeric [DT_NUMERIC]
12
2
OK
Drag and drop a Data Flow task
onto the Control Flow tab and name it as File to database - With Cedilla delimiter
. Disable the first data flow task.
Configure the second data flow task with Flat File Source
and OLE DB Destination
Double-click the Flat File Source to open Flat File Source Editor
. On the Connection Manager
page of the Flat File Source Editor, select the Flat File Connection Manager ProductListPrice_Cedilla
and click Columns page to configure the columns. Click OK
.
Execute the package. All the components will display green color to indicate that the process was success but no rows will be processed. You can see that there are no rows numbers indication between the Flat File Source
and OLE DB Destination
Click the Progress
tab and you will notice the following warning message.
[Read flat file [1]] Warning: The end of the data file was reached while
reading header rows. Make sure the header row delimiter and the number of
header rows to skip are correct.
Answer above seems awfully complicated, just convert the line endings in the file
Dim FileContents As String = My.Computer.FileSystem.ReadAllText("c:\Temp\UnixFile.csv")
Dim NewFileContents As String = FileContents.Replace(vbLf, vbCrLf)
My.Computer.FileSystem.WriteAllText("c:\temp\WindowsFile.csv", NewFileContents, False, New System.Text.UnicodeEncoding)
Rehashed from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With